mirror of
https://github.com/python/cpython.git
synced 2025-08-16 23:01:34 +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
|
@ -17,6 +17,7 @@ import copy
|
|||
import socket
|
||||
import random
|
||||
import logging
|
||||
from StringIO import StringIO
|
||||
|
||||
|
||||
# Work around broken sem_open implementations
|
||||
|
@ -1829,7 +1830,73 @@ class OtherTest(unittest.TestCase):
|
|||
multiprocessing.connection.answer_challenge,
|
||||
_FakeConnection(), b'abc')
|
||||
|
||||
testcases_other = [OtherTest, TestInvalidHandle]
|
||||
#
|
||||
# Issue 5155, 5313, 5331: Test process in processes
|
||||
# Verifies os.close(sys.stdin.fileno) vs. sys.stdin.close() behavior
|
||||
#
|
||||
|
||||
def _ThisSubProcess(q):
|
||||
try:
|
||||
item = q.get(block=False)
|
||||
except Queue.Empty:
|
||||
pass
|
||||
|
||||
def _TestProcess(q):
|
||||
queue = multiprocessing.Queue()
|
||||
subProc = multiprocessing.Process(target=_ThisSubProcess, args=(queue,))
|
||||
subProc.start()
|
||||
subProc.join()
|
||||
|
||||
def _afunc(x):
|
||||
return x*x
|
||||
|
||||
def pool_in_process():
|
||||
pool = multiprocessing.Pool(processes=4)
|
||||
x = pool.map(_afunc, [1, 2, 3, 4, 5, 6, 7])
|
||||
|
||||
class _file_like(object):
|
||||
def __init__(self, delegate):
|
||||
self._delegate = delegate
|
||||
self._pid = None
|
||||
|
||||
@property
|
||||
def cache(self):
|
||||
pid = os.getpid()
|
||||
# There are no race conditions since fork keeps only the running thread
|
||||
if pid != self._pid:
|
||||
self._pid = pid
|
||||
self._cache = []
|
||||
return self._cache
|
||||
|
||||
def write(self, data):
|
||||
self.cache.append(data)
|
||||
|
||||
def flush(self):
|
||||
self._delegate.write(''.join(self.cache))
|
||||
self._cache = []
|
||||
|
||||
class TestStdinBadfiledescriptor(unittest.TestCase):
|
||||
|
||||
def test_queue_in_process(self):
|
||||
queue = multiprocessing.Queue()
|
||||
proc = multiprocessing.Process(target=_TestProcess, args=(queue,))
|
||||
proc.start()
|
||||
proc.join()
|
||||
|
||||
def test_pool_in_process(self):
|
||||
p = multiprocessing.Process(target=pool_in_process)
|
||||
p.start()
|
||||
p.join()
|
||||
|
||||
def test_flushing(self):
|
||||
sio = StringIO()
|
||||
flike = _file_like(sio)
|
||||
flike.write('foo')
|
||||
proc = multiprocessing.Process(target=lambda: flike.flush())
|
||||
flike.flush()
|
||||
assert sio.getvalue() == 'foo'
|
||||
|
||||
testcases_other = [OtherTest, TestInvalidHandle, TestStdinBadfiledescriptor]
|
||||
|
||||
#
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue