Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

-Werror doesn't error out on DeprecationWarning for os.fork() #135427

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
@fperrin

Description

@fperrin

Bug report

Bug description:

Hi,

With the recent change that Python now throws a warning for programs that fork() when there are more than one threads. I was hoping to use-Werror to find and pinpoint all such occurrences in my software.

Using python3.13 as installed by uv (cpython-3.13.4-linux-x86_64-gnu). With the following test code:

importos,sys,threading,timet=threading.Thread(target=time.sleep,args=(1,),daemon=True)t.start()assertthreading.active_count()==2pid=os.fork()ifpid<0:print(f"fork failed:{pid=}")elifpid==0:print(f"after fork, I am{os.getpid()=};{threading.active_count()=}")sys.exit(0)print(f"successful fork; I am{os.getpid()=}, child is{pid=};{threading.active_count()=}")pid,_=os.forkpty()ifpid<0:print(f"forkpty failed:{pid=}")elifpid==0:print(f"after forkpty, I am{os.getpid()=};{threading.active_count()=}")sys.exit(0)print(f"successful forkpty; I am{os.getpid()=}, child is{pid=};{threading.active_count()=}")

Running with-Walways gives me the expected warnings:

$ python3 -Walways ex.py after fork, I am os.getpid()=275006; threading.active_count()=1/home/fred/demo/ex.py:8: DeprecationWarning: This process (pid=275004) is multi-threaded, use of fork() may lead to deadlocks in the child.  pid = os.fork()successful fork; I am os.getpid()=275004, child is pid=275006; threading.active_count()=2/home/fred/demo/ex.py:16: DeprecationWarning: This process (pid=275004) is multi-threaded, use of forkpty() may lead to deadlocks in the child.  pid, _ = os.forkpty()successful forkpty; I am os.getpid()=275004, child is pid=275007; threading.active_count()=2

However, running with-Werror, the code silently run (no exception raised, no warning printed):

$ python3 --versionPython 3.13.4$ python3 -Werror ex.py successful fork; I am os.getpid()=275060, child is pid=275062; threading.active_count()=2after fork, I am os.getpid()=275062; threading.active_count()=1successful forkpty; I am os.getpid()=275060, child is pid=275063; threading.active_count()=2

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp