mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
Merged revisions 73708,73738 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r73708 | jesse.noller | 2009-06-30 13:11:52 -0400 (Tue, 30 Jun 2009) | 1 line Resolves issues 5155, 5313, 5331 - bad file descriptor error with processes in processes ........ r73738 | r.david.murray | 2009-06-30 22:49:10 -0400 (Tue, 30 Jun 2009) | 2 lines Make punctuation prettier and break up run-on sentence. ........
This commit is contained in:
parent
f37b563c72
commit
17438dc26c
5 changed files with 109 additions and 2 deletions
|
@ -2087,6 +2087,38 @@ Explicitly pass resources to child processes
|
|||
for i in range(10):
|
||||
Process(target=f, args=(lock,)).start()
|
||||
|
||||
Beware replacing sys.stdin with a "file like object"
|
||||
|
||||
:mod:`multiprocessing` originally unconditionally called::
|
||||
|
||||
os.close(sys.stdin.fileno())
|
||||
|
||||
in the :meth:`multiprocessing.Process._bootstrap` method --- this resulted
|
||||
in issues with processes-in-processes. This has been changed to::
|
||||
|
||||
sys.stdin.close()
|
||||
sys.stdin = open(os.devnull)
|
||||
|
||||
Which solves the fundamental issue of processes colliding with each other
|
||||
resulting in a bad file descriptor error, but introduces a potential danger
|
||||
to applications which replace :func:`sys.stdin` with a "file-like object"
|
||||
with output buffering. This danger is that if multiple processes call
|
||||
:func:`close()` on this file-like object, it could result in the same
|
||||
data being flushed to the object multiple times, resulting in corruption.
|
||||
|
||||
If you write a file-like object and implement your own caching, you can
|
||||
make it fork-safe by storing the pid whenever you append to the cache,
|
||||
and discarding the cache when the pid changes. For example::
|
||||
|
||||
@property
|
||||
def cache(self):
|
||||
pid = os.getpid()
|
||||
if pid != self._pid:
|
||||
self._pid = pid
|
||||
self._cache = []
|
||||
return self._cache
|
||||
|
||||
For more information, see :issue:`5155`, :issue:`5313` and :issue:`5331`
|
||||
|
||||
Windows
|
||||
~~~~~~~
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue