mercurial/vfs.py
changeset 35426 60f2a215faa7
parent 34645 75979c8d4572
child 35625 390f860228ba
equal deleted inserted replaced
35424:702e6d2642e7 35426:60f2a215faa7
   275 
   275 
   276         When this context manager is active, ``backgroundclose`` can be passed
   276         When this context manager is active, ``backgroundclose`` can be passed
   277         to ``__call__``/``open`` to result in the file possibly being closed
   277         to ``__call__``/``open`` to result in the file possibly being closed
   278         asynchronously, on a background thread.
   278         asynchronously, on a background thread.
   279         """
   279         """
   280         # This is an arbitrary restriction and could be changed if we ever
   280         # Sharing backgroundfilecloser between threads is complex and using
   281         # have a use case.
   281         # multiple instances puts us at risk of running out of file descriptors
       
   282         # only allow to use backgroundfilecloser when in main thread.
       
   283         if not isinstance(threading.currentThread(), threading._MainThread):
       
   284             yield
       
   285             return
   282         vfs = getattr(self, 'vfs', self)
   286         vfs = getattr(self, 'vfs', self)
   283         if getattr(vfs, '_backgroundfilecloser', None):
   287         if getattr(vfs, '_backgroundfilecloser', None):
   284             raise error.Abort(
   288             raise error.Abort(
   285                 _('can only have 1 active background file closer'))
   289                 _('can only have 1 active background file closer'))
   286 
   290 
   411             if mode in ('r', 'rb'):
   415             if mode in ('r', 'rb'):
   412                 raise error.Abort(_('implementation error: mode %s is not'
   416                 raise error.Abort(_('implementation error: mode %s is not'
   413                                     ' valid for checkambig=True') % mode)
   417                                     ' valid for checkambig=True') % mode)
   414             fp = checkambigatclosing(fp)
   418             fp = checkambigatclosing(fp)
   415 
   419 
   416         if backgroundclose:
   420         if (backgroundclose and
       
   421                 isinstance(threading.currentThread(), threading._MainThread)):
   417             if not self._backgroundfilecloser:
   422             if not self._backgroundfilecloser:
   418                 raise error.Abort(_('backgroundclose can only be used when a '
   423                 raise error.Abort(_('backgroundclose can only be used when a '
   419                                   'backgroundclosing context manager is active')
   424                                   'backgroundclosing context manager is active')
   420                                   )
   425                                   )
   421 
   426