Skip to content

fix incorrect main thread id value in mp.Process #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion uvloop/includes/stdlib.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ cdef int ssl_SSL_ERROR_WANT_READ = ssl.SSL_ERROR_WANT_READ
cdef int ssl_SSL_ERROR_WANT_WRITE = ssl.SSL_ERROR_WANT_WRITE
cdef int ssl_SSL_ERROR_SYSCALL = ssl.SSL_ERROR_SYSCALL

cdef uint64_t MAIN_THREAD_ID = <uint64_t><int64_t>threading.main_thread().ident
cdef threading_Thread = threading.Thread
cdef threading_main_thread = threading.main_thread

cdef int subprocess_PIPE = subprocess.PIPE
cdef int subprocess_STDOUT = subprocess.STDOUT
Expand Down
1 change: 0 additions & 1 deletion uvloop/loop.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ cdef class Loop:
bint _stopping

uint64_t _thread_id
bint _thread_is_main

object _task_factory
object _exception_handler
Expand Down
9 changes: 2 additions & 7 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ cdef class Loop:

self._closed = 0
self._debug = 0
self._thread_is_main = 0
self._thread_id = 0
self._running = 0
self._stopping = 0
Expand Down Expand Up @@ -216,7 +215,7 @@ cdef class Loop:
self._servers = set()

cdef inline _is_main_thread(self):
return MAIN_THREAD_ID == PyThread_get_thread_ident()
return threading_main_thread().ident == PyThread_get_thread_ident()

def __init__(self):
self.set_debug((not sys_ignore_environment
Expand Down Expand Up @@ -520,7 +519,6 @@ cdef class Loop:
self._last_error = None

self._thread_id = PyThread_get_thread_ident()
self._thread_is_main = MAIN_THREAD_ID == self._thread_id
self._running = 1

self.handler_check__exec_writes.start()
Expand All @@ -541,7 +539,6 @@ cdef class Loop:

self._pause_signals()

self._thread_is_main = 0
self._thread_id = 0
self._running = 0
self._stopping = 0
Expand Down Expand Up @@ -3287,16 +3284,14 @@ cdef Loop __forking_loop = None


cdef void __get_fork_handler() nogil:
global __forking
global __forking_loop

with gil:
if (__forking and __forking_loop is not None and
__forking_loop.active_process_handler is not None):
__forking_loop.active_process_handler._after_fork()

cdef __install_atfork():
global __atfork_installed

if __atfork_installed:
return
__atfork_installed = 1
Expand Down