Skip to content

Commit 898b310

Browse files
committed
add gil technqiue for windows to simulate forking
1 parent d3c2b4a commit 898b310

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

uvloop/handles/process.pyx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,33 @@ cdef class UVProcess(UVHandle):
9191
self._restore_signals = restore_signals
9292

9393
loop.active_process_handler = self
94-
__forking = 1
95-
__forking_loop = loop
94+
9695

9796
if not system.PLATFORM_IS_WINDOWS:
97+
__forking = 1
98+
__forking_loop = loop
9899
system.setForkHandler(<system.OnForkHandler>&__get_fork_handler)
99100

100101
PyOS_BeforeFork()
102+
else:
103+
py_gil_state = PyGILState_Ensure()
101104

102105
err = uv.uv_spawn(loop.uvloop,
103106
<uv.uv_process_t*>self._handle,
104107
&self.options)
105108

106-
__forking = 0
107-
__forking_loop = None
109+
108110
if not system.PLATFORM_IS_WINDOWS:
109-
111+
__forking = 0
112+
__forking_loop = None
110113
system.resetForkHandler()
111114

112115
PyOS_AfterFork_Parent()
116+
else:
117+
PyGILState_Release(py_gil_state)
113118

114-
119+
loop.active_process_handler = None
120+
115121

116122
if err < 0:
117123
self._close_process_handle()

uvloop/loop.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ from libc.stdint cimport uint64_t
2828
from libc.string cimport memset, strerror, memcpy
2929
from libc cimport errno
3030

31+
# Winloop Comment: We need some cleaver hacky techniques for
32+
# preventing slow spawnning processes for MSVC
33+
from cpython.pystate cimport (PyGILState_Ensure, PyGILState_Release,
34+
PyGILState_STATE)
3135
from cpython cimport PyObject
3236
from cpython cimport PyErr_CheckSignals, PyErr_Occurred
3337
from cpython cimport PyThread_get_thread_ident

0 commit comments

Comments
 (0)