changeset 51883:1edac12af730

vfs: modernize the detection of the main thread There weren't a lot of good choices when py27 was supported, but starting with py34, `threading.main_thread()` is available. This gets us away from an undocumented, internal symbol, and drops a pytype suppression statement. It is also apparently no longer reliable after a process fork.[1][2] [1] https://stackoverflow.com/a/23207116 [2] https://github.com/python/cpython/blob/v3.6.3/Lib/threading.py#L1334
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 19 Sep 2024 21:03:10 -0400
parents 2391a5fa111e
children f79f98733a5b
files mercurial/vfs.py
diffstat 1 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/vfs.py	Sun Sep 22 17:06:31 2024 -0400
+++ b/mercurial/vfs.py	Thu Sep 19 21:03:10 2024 -0400
@@ -373,10 +373,7 @@
         # Sharing backgroundfilecloser between threads is complex and using
         # multiple instances puts us at risk of running out of file descriptors
         # only allow to use backgroundfilecloser when in main thread.
-        if not isinstance(
-            threading.current_thread(),
-            threading._MainThread,  # pytype: disable=module-attr
-        ):
+        if threading.current_thread() is not threading.main_thread():
             yield
             return
         vfs = getattr(self, 'vfs', self)
@@ -575,9 +572,9 @@
                 )
             fp = checkambigatclosing(fp)
 
-        if backgroundclose and isinstance(
-            threading.current_thread(),
-            threading._MainThread,  # pytype: disable=module-attr
+        if (
+            backgroundclose
+            and threading.current_thread() is threading.main_thread()
         ):
             if (
                 not self._backgroundfilecloser  # pytype: disable=attribute-error