Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Open
Description
Bug report
Bug description:
I'm experiencing an issue specifically in python 3.13 regarding Threads in the context of multiprocessing.
The following code is working in python < 3.13
frommultiprocessingimportProcessfromthreadingimportThreadimporttimeclassMyThread(Thread):def__init__(self):Thread.__init__(self)self.__data=''defrun(self):print("Hi from thread")print(self.__data)classAclass():def__init__(self):self._t=MyThread()self._t.daemon=Truedefstart(self):self._t.start()print("thread started")if__name__=='__main__':t=Aclass()p=Process(target=t.start )p.start()time.sleep(2)
After executing the above in python 3.13 I get this output:
File "/usr/lib/python3.13/multiprocessing/process.py", line 313, in _bootstrap self.run() ~~~~~~~~^^ File "/usr/lib/python3.13/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/impacket/master/impacket/tests/SMB_RPC/test_bug_process_thread.py", line 18, in start self._t.start() ~~~~~~~~~~~~~^^ File "/usr/lib/python3.13/threading.py", line 973, in start _start_joinable_thread(self._bootstrap, handle=self._handle, ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ daemon=self.daemon) ^^^^^^^^^^^^^^^^^^^RuntimeError: thread already started
I managed to workaround this by delaying the Thread instance initialization, moving the Thread.init() call to start() method in the derived class, so everything gets executed in the context of the child process.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-134381: Improve thread safety in _PyThread_AfterFork by preserving not-started handles #134514
- [3.14] gh-134381: Fix RuntimeError when starting not-yet started Thread after fork (gh-134514) #134596
- [3.13] gh-134381: Fix RuntimeError when starting not-yet started Thread after fork (gh-134514) #134597