File tree Expand file tree Collapse file tree 2 files changed +9
-22
lines changed Expand file tree Collapse file tree 2 files changed +9
-22
lines changed Original file line number Diff line number Diff line change 1
1
"""Thread module emulating a subset of Java's threading model."""
2
2
3
+ import os as _os
3
4
import sys as _sys
4
5
import _thread
5
6
@@ -943,6 +944,7 @@ def _bootstrap_inner(self):
943
944
exc_tb .tb_frame .f_code .co_name )), file = self ._stderr )
944
945
exc_tb = exc_tb .tb_next
945
946
print (("%s: %s" % (exc_type , exc_value )), file = self ._stderr )
947
+ self ._stderr .flush ()
946
948
# Make sure that exc_tb gets deleted since it is a memory
947
949
# hog; deleting everything else is just for thoroughness
948
950
finally :
@@ -1319,10 +1321,9 @@ def main_thread():
1319
1321
1320
1322
1321
1323
def _after_fork ():
1322
- # This function is called by Python/ceval.c:PyEval_ReInitThreads which
1323
- # is called from PyOS_AfterFork_Child. Here we cleanup threading module
1324
- # state that should not exist after a fork.
1325
-
1324
+ """
1325
+ Cleanup threading module state that should not exist after a fork.
1326
+ """
1326
1327
# Reset _active_limbo_lock, in case we forked while the lock was held
1327
1328
# by another (non-forked) thread. http://bugs.python.org/issue874900
1328
1329
global _active_limbo_lock , _main_thread
@@ -1356,3 +1357,7 @@ def _after_fork():
1356
1357
_active .clear ()
1357
1358
_active .update (new_active )
1358
1359
assert len (_active ) == 1
1360
+
1361
+
1362
+ if hasattr (_os , "fork" ):
1363
+ _os .register_at_fork (_after_fork , when = "child" )
Original file line number Diff line number Diff line change @@ -240,8 +240,6 @@ PyEval_ReleaseThread(PyThreadState *tstate)
240
240
void
241
241
PyEval_ReInitThreads (void )
242
242
{
243
- _Py_IDENTIFIER (_after_fork );
244
- PyObject * threading , * result ;
245
243
PyThreadState * current_tstate = PyThreadState_GET ();
246
244
247
245
if (!gil_created ())
@@ -251,22 +249,6 @@ PyEval_ReInitThreads(void)
251
249
take_gil (current_tstate );
252
250
main_thread = PyThread_get_thread_ident ();
253
251
254
- /* Update the threading module with the new state.
255
- */
256
- threading = PyMapping_GetItemString (current_tstate -> interp -> modules ,
257
- "threading" );
258
- if (threading == NULL ) {
259
- /* threading not imported */
260
- PyErr_Clear ();
261
- return ;
262
- }
263
- result = _PyObject_CallMethodId (threading , & PyId__after_fork , NULL );
264
- if (result == NULL )
265
- PyErr_WriteUnraisable (threading );
266
- else
267
- Py_DECREF (result );
268
- Py_DECREF (threading );
269
-
270
252
/* Destroy all threads except the current one */
271
253
_PyThreadState_DeleteExcept (current_tstate );
272
254
}
You can’t perform that action at this time.
0 commit comments