File tree Expand file tree Collapse file tree 4 files changed +33
-17
lines changed Expand file tree Collapse file tree 4 files changed +33
-17
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ cdef class UVProcess(UVHandle):
7777 __forking = 1
7878 __forking_loop = loop
7979
80- _PyImport_AcquireLock ()
80+ PyOS_BeforeFork ()
8181
8282 err = uv.uv_spawn(loop.uvloop,
8383 < uv.uv_process_t* > self ._handle,
@@ -87,14 +87,7 @@ cdef class UVProcess(UVHandle):
8787 __forking_loop = None
8888 loop.active_process_handler = None
8989
90- if _PyImport_ReleaseLock() < 0 :
91- # See CPython/posixmodule.c for details
92- self ._close_process_handle()
93- if err < 0 :
94- self ._abort_init()
95- else :
96- self ._close()
97- raise RuntimeError (' not holding the import lock' )
90+ PyOS_AfterFork_Parent()
9891
9992 if err < 0 :
10093 self ._close_process_handle()
@@ -176,7 +169,7 @@ cdef class UVProcess(UVHandle):
176169 if self ._restore_signals:
177170 _Py_RestoreSignals()
178171
179- PyOS_AfterFork ()
172+ PyOS_AfterFork_Child ()
180173
181174 err = uv.uv_loop_fork(self ._loop.uvloop)
182175 if err < 0 :
Original file line number Diff line number Diff line change @@ -79,3 +79,26 @@ int Context_Exit(PyObject *ctx) {
7979}
8080
8181#endif
82+
83+
84+ #if PY_VERSION_HEX < 0x03070000
85+
86+ void PyOS_BeforeFork (void )
87+ {
88+ _PyImport_AcquireLock ();
89+ }
90+
91+ void PyOS_AfterFork_Parent (void )
92+ {
93+ if (_PyImport_ReleaseLock () <= 0 ) {
94+ Py_FatalError ("failed releasing import lock after fork" );
95+ }
96+ }
97+
98+
99+ void PyOS_AfterFork_Child (void )
100+ {
101+ PyOS_AfterFork ();
102+ }
103+
104+ #endif
Original file line number Diff line number Diff line change @@ -9,9 +9,6 @@ cdef extern from "Python.h":
99 object PyUnicode_EncodeFSDefault(object )
1010 void PyErr_SetInterrupt() nogil
1111
12- void PyOS_AfterFork()
13- void _PyImport_AcquireLock()
14- int _PyImport_ReleaseLock()
1512 void _Py_RestoreSignals()
1613
1714 object PyMemoryView_FromMemory(char * mem, ssize_t size, int flags)
@@ -26,3 +23,7 @@ cdef extern from "includes/compat.h":
2623 object Context_CopyCurrent()
2724 int Context_Enter(object ) except - 1
2825 int Context_Exit(object ) except - 1
26+
27+ void PyOS_BeforeFork()
28+ void PyOS_AfterFork_Parent()
29+ void PyOS_AfterFork_Child()
Original file line number Diff line number Diff line change @@ -11,15 +11,14 @@ from .includes.python cimport PY_VERSION_HEX, \
1111 PyMem_RawCalloc, PyMem_RawRealloc, \
1212 PyUnicode_EncodeFSDefault, \
1313 PyErr_SetInterrupt, \
14- PyOS_AfterFork, \
15- _PyImport_AcquireLock, \
16- _PyImport_ReleaseLock, \
1714 _Py_RestoreSignals, \
1815 Context_CopyCurrent, \
1916 Context_Enter, \
2017 Context_Exit, \
2118 PyMemoryView_FromMemory, PyBUF_WRITE, \
22- PyMemoryView_FromObject, PyMemoryView_Check
19+ PyMemoryView_FromObject, PyMemoryView_Check, \
20+ PyOS_AfterFork_Parent, PyOS_AfterFork_Child, \
21+ PyOS_BeforeFork
2322from .includes.flowcontrol cimport add_flowcontrol_defaults
2423
2524from libc.stdint cimport uint64_t
You can’t perform that action at this time.
0 commit comments