Skip to content

AsyncIO REPL does not respect $PYTHONSTARTUP on 3.12.3 #142639

Closed as not planned
Closed as not planned

Description

@TahaAhmedRasheed

Bug report

Bug description:

Script to reproduce:

#!/usr/bin/env bash
echo "Python version: $(python3 --version)"
cd $(mktemp -d)
echo "PWD is $PWD"
echo 'x=5' > startup.py
PYTHONSTARTUP="startup.py" python3
PYTHONSTARTUP="startup.py" python3 -m asyncio
cd - > /dev/null
echo "PWD is $PWD"

Current behaviour

$ ./repro.sh
Python version: Python 3.12.3
PWD is /tmp/tmp.lVtvc63MZq
Python 3.12.3 (main, Nov  6 2025, 13:44:16) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x
5
>>> ^D
asyncio REPL 3.12.3 (main, Nov  6 2025, 13:44:16) [GCC 13.3.0] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> x
Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/__main__.py", line 58, in runcode
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.12/asyncio/__main__.py", line 34, in callback
    coro = func()
           ^^^^^^
  File "<console>", line 1, in <module>
NameError: name 'x' is not defined
>>> ^D
exiting asyncio REPL...
PWD is /tmp/tmp.1fcA8GVU2A
$

Expected behaviour
For x to be defined and set to 5, like in the regular non-asyncio REPL.

OS info

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.2 LTS"
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
$ uname -a
Linux ROG 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Activity

  1. zware commented on Dec 12, 2025

    @zware
    Member

    Can you reproduce this with either 3.13 or 3.14? 3.12 is no longer receiving non-security fixes.

    Note that with the new REPL in 3.13, there's an additional dimension to the testing matrix; we'll need to check with and without PYTHON_BASIC_REPL=1.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    on Dec 12, 2025
  3. dr-carlos commented on Dec 12, 2025

    @dr-carlos
    Contributor

    Can you reproduce this with either 3.13 or 3.14? 3.12 is no longer receiving non-security fixes.

    Note that with the new REPL in 3.13, there's an additional dimension to the testing matrix; we'll need to check with and without PYTHON_BASIC_REPL=1.

    Doesn't seem to occur on Python 3.13/3.14 with or without PYTHON_BASIC_REPL=1 enabled.

  4. johnslavik commented on Dec 12, 2025

    @johnslavik
    Member

    Yes, the support for PYTHONSTARTUP in the asyncio REPL was added in GH-119433 (backported to 3.13, but not 3.12).

    I think we can close this (cc @ZeroIntensity, @ambv).

  5. moved this from Todo to Done in asyncioon Dec 12, 2025
  6. TahaAhmedRasheed commented on Dec 13, 2025

    @TahaAhmedRasheed
    Author

    @johnslavik Is there any way I could manually backport the fix to my existing Python installation?

  7. ZeroIntensity commented on Dec 13, 2025

    @ZeroIntensity
    Member

    I assume you would need to backport all of _pyrepl. Why not just use 3.13?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions