Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
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()=2However, 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()=2CPython versions tested on:
3.13
Operating systems tested on:
Linux