[Python-checkins] bpo-38951: Use threading.main_thread() check in asyncio (GH-17433)

Miss Islington (bot) webhook-mailer at python.org
Thu Dec 5 07:40:40 EST 2019


https://github.com/python/cpython/commit/99eb70a9eb9493602ff6ad8bb92df4318cf05a3e
commit: 99eb70a9eb9493602ff6ad8bb92df4318cf05a3e
branch: master
author: Hill Ma <mahiuchun at users.noreply.github.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019-12-05T04:40:12-08:00
summary:

bpo-38951: Use threading.main_thread() check in asyncio (GH-17433)



https://bugs.python.org/issue38951

files:
M Lib/asyncio/events.py
M Lib/asyncio/unix_events.py

diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 36b7ea307e03b..c7343f515ca22 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -636,7 +636,7 @@ def get_event_loop(self):
         """
         if (self._local._loop is None and
                 not self._local._set_called and
-                isinstance(threading.current_thread(), threading._MainThread)):
+                threading.current_thread() is threading.main_thread()):
             self.set_event_loop(self.new_event_loop())
 
         if self._local._loop is None:
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 632546ad00817..97198ea2f4953 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -1406,8 +1406,7 @@ def _init_watcher(self):
         with events._lock:
             if self._watcher is None:  # pragma: no branch
                 self._watcher = ThreadedChildWatcher()
-                if isinstance(threading.current_thread(),
-                              threading._MainThread):
+                if threading.current_thread() is threading.main_thread():
                     self._watcher.attach_loop(self._local._loop)
 
     def set_event_loop(self, loop):
@@ -1421,7 +1420,7 @@ def set_event_loop(self, loop):
         super().set_event_loop(loop)
 
         if (self._watcher is not None and
-                isinstance(threading.current_thread(), threading._MainThread)):
+                threading.current_thread() is threading.main_thread()):
             self._watcher.attach_loop(loop)
 
     def get_child_watcher(self):



More information about the Python-checkins mailing list