Skip to content

Commit 99eb70a

Browse files
mahiuchunmiss-islington
authored andcommitted
bpo-38951: Use threading.main_thread() check in asyncio (GH-17433)
https://bugs.python.org/issue38951
1 parent bb81549 commit 99eb70a

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Lib/asyncio/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def get_event_loop(self):
636636
"""
637637
if (self._local._loop is None and
638638
not self._local._set_called and
639-
isinstance(threading.current_thread(), threading._MainThread)):
639+
threading.current_thread() is threading.main_thread()):
640640
self.set_event_loop(self.new_event_loop())
641641

642642
if self._local._loop is None:

Lib/asyncio/unix_events.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,7 @@ def _init_watcher(self):
14061406
with events._lock:
14071407
if self._watcher is None: # pragma: no branch
14081408
self._watcher = ThreadedChildWatcher()
1409-
if isinstance(threading.current_thread(),
1410-
threading._MainThread):
1409+
if threading.current_thread() is threading.main_thread():
14111410
self._watcher.attach_loop(self._local._loop)
14121411

14131412
def set_event_loop(self, loop):
@@ -1421,7 +1420,7 @@ def set_event_loop(self, loop):
14211420
super().set_event_loop(loop)
14221421

14231422
if (self._watcher is not None and
1424-
isinstance(threading.current_thread(), threading._MainThread)):
1423+
threading.current_thread() is threading.main_thread()):
14251424
self._watcher.attach_loop(loop)
14261425

14271426
def get_child_watcher(self):

0 commit comments

Comments
 (0)