D1457: workers: don't use backgroundfilecloser in threads

2017-12-15 Thread wlis (Wojciech Lis)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG60f2a215faa7: workers: dont use backgroundfilecloser 
in threads (authored by wlis, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1457?vs=4386=4484

REVISION DETAIL
  https://phab.mercurial-scm.org/D1457

AFFECTED FILES
  mercurial/vfs.py

CHANGE DETAILS

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -277,8 +277,12 @@
 to ``__call__``/``open`` to result in the file possibly being closed
 asynchronously, on a background thread.
 """
-# This is an arbitrary restriction and could be changed if we ever
-# have a use case.
+# 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.currentThread(), threading._MainThread):
+yield
+return
 vfs = getattr(self, 'vfs', self)
 if getattr(vfs, '_backgroundfilecloser', None):
 raise error.Abort(
@@ -413,7 +417,8 @@
 ' valid for checkambig=True') % mode)
 fp = checkambigatclosing(fp)
 
-if backgroundclose:
+if (backgroundclose and
+isinstance(threading.currentThread(), threading._MainThread)):
 if not self._backgroundfilecloser:
 raise error.Abort(_('backgroundclose can only be used when a '
   'backgroundclosing context manager is 
active')



To: wlis, #hg-reviewers, indygreg, krbullock
Cc: krbullock, durin42, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D1457: workers: don't use backgroundfilecloser in threads

2017-12-12 Thread wlis (Wojciech Lis)
wlis updated this revision to Diff 4386.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1457?vs=4022=4386

REVISION DETAIL
  https://phab.mercurial-scm.org/D1457

AFFECTED FILES
  mercurial/vfs.py

CHANGE DETAILS

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -277,8 +277,12 @@
 to ``__call__``/``open`` to result in the file possibly being closed
 asynchronously, on a background thread.
 """
-# This is an arbitrary restriction and could be changed if we ever
-# have a use case.
+# 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.currentThread(), threading._MainThread):
+yield
+return
 vfs = getattr(self, 'vfs', self)
 if getattr(vfs, '_backgroundfilecloser', None):
 raise error.Abort(
@@ -413,7 +417,8 @@
 ' valid for checkambig=True') % mode)
 fp = checkambigatclosing(fp)
 
-if backgroundclose:
+if (backgroundclose and
+isinstance(threading.currentThread(), threading._MainThread)):
 if not self._backgroundfilecloser:
 raise error.Abort(_('backgroundclose can only be used when a '
   'backgroundclosing context manager is 
active')



To: wlis, #hg-reviewers, indygreg, krbullock
Cc: krbullock, durin42, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D1457: workers: don't use backgroundfilecloser in threads

2017-12-08 Thread krbullock (Kevin Bullock)
krbullock requested changes to this revision.
krbullock added a comment.
This revision now requires changes to proceed.


  Looks okay to me except for Augie's nit. @indygreg ?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1457

To: wlis, #hg-reviewers, indygreg, krbullock
Cc: krbullock, durin42, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D1457: workers: don't use backgroundfilecloser in threads

2017-12-05 Thread durin42 (Augie Fackler)
durin42 added inline comments.

INLINE COMMENTS

> vfs.py:420
>  
> -if backgroundclose:
> +if backgroundclose and \
> +isinstance(threading.currentThread(), threading._MainThread):

nit: wrap lines using () instead of \, eg

if (backgroundclose and

  isinstance(...)):

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1457

To: wlis, #hg-reviewers, indygreg
Cc: durin42, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D1457: workers: don't use backgroundfilecloser in threads

2017-11-30 Thread wlis (Wojciech Lis)
wlis updated this revision to Diff 4022.
wlis edited the summary of this revision.
wlis retitled this revision from "workers: create backgroundcloser per thread" 
to "workers: don't use backgroundfilecloser in threads".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1457?vs=3664=4022

REVISION DETAIL
  https://phab.mercurial-scm.org/D1457

AFFECTED FILES
  mercurial/vfs.py

CHANGE DETAILS

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -277,8 +277,12 @@
 to ``__call__``/``open`` to result in the file possibly being closed
 asynchronously, on a background thread.
 """
-# This is an arbitrary restriction and could be changed if we ever
-# have a use case.
+# 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.currentThread(), threading._MainThread):
+yield
+return
 vfs = getattr(self, 'vfs', self)
 if getattr(vfs, '_backgroundfilecloser', None):
 raise error.Abort(
@@ -413,7 +417,8 @@
 ' valid for checkambig=True') % mode)
 fp = checkambigatclosing(fp)
 
-if backgroundclose:
+if backgroundclose and \
+isinstance(threading.currentThread(), threading._MainThread):
 if not self._backgroundfilecloser:
 raise error.Abort(_('backgroundclose can only be used when a '
   'backgroundclosing context manager is 
active')



To: wlis, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel