Skip to content

Commit 3e6a043

Browse files
committed
Use higher-level wrappers for the __forkHandler global
1 parent bed926c commit 3e6a043

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

uvloop/handles/process.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cdef class UVProcess(UVHandle):
7777
loop.active_process_handler = self
7878
__forking = 1
7979
__forking_loop = loop
80-
__forkHandler = <OnForkHandler>&__get_fork_handler
80+
system.setForkHandler(<system.OnForkHandler>&__get_fork_handler)
8181

8282
PyOS_BeforeFork()
8383

@@ -87,7 +87,7 @@ cdef class UVProcess(UVHandle):
8787

8888
__forking = 0
8989
__forking_loop = None
90-
__forkHandler = NULL
90+
system.resetForkHandler()
9191
loop.active_process_handler = None
9292

9393
PyOS_AfterFork_Parent()

uvloop/includes/fork_handler.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@ OnForkHandler __forkHandler = NULL;
88
Note: Fork handler needs to be in C (not cython) otherwise it would require
99
GIL to be present, but some forks can exec non-python processes.
1010
*/
11-
void handleAtFork() {
11+
void handleAtFork(void) {
1212
if (__forkHandler != NULL) {
1313
__forkHandler();
1414
}
1515
}
16+
17+
18+
void setForkHandler(OnForkHandler handler)
19+
{
20+
__forkHandler = handler;
21+
}
22+
23+
24+
void resetForkHandler(void)
25+
{
26+
__forkHandler = NULL;
27+
}

uvloop/includes/system.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ cdef extern from "includes/compat.h" nogil:
8181
int EPOLL_CTL_DEL
8282
int epoll_ctl(int epfd, int op, int fd, epoll_event *event)
8383
object MakeUnixSockPyAddr(sockaddr_un *addr)
84+
85+
86+
cdef extern from "includes/fork_handler.h":
87+
88+
ctypedef void (*OnForkHandler)()
89+
void handleAtFork()
90+
void setForkHandler(OnForkHandler handler)
91+
void resetForkHandler()

uvloop/loop.pyx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3178,11 +3178,6 @@ cdef vint __atfork_installed = 0
31783178
cdef vint __forking = 0
31793179
cdef Loop __forking_loop = None
31803180

3181-
cdef extern from "includes/fork_handler.h":
3182-
3183-
ctypedef void (*OnForkHandler)()
3184-
cdef OnForkHandler __forkHandler
3185-
void handleAtFork()
31863181

31873182
cdef void __get_fork_handler() nogil:
31883183
global __forking
@@ -3201,7 +3196,7 @@ cdef __install_atfork():
32013196

32023197
cdef int err
32033198

3204-
err = system.pthread_atfork(NULL, NULL, &handleAtFork)
3199+
err = system.pthread_atfork(NULL, NULL, &system.handleAtFork)
32053200
if err:
32063201
__atfork_installed = 0
32073202
raise convert_error(-err)

0 commit comments

Comments
 (0)