本文整理匯總了Python中multiprocessing.util.ForkAwareThreadLock方法的典型用法代碼示例。如果您正苦於以下問題:Python util.ForkAwareThreadLock方法的具體用法?Python util.ForkAwareThreadLock怎麽用?Python util.ForkAwareThreadLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing.util
的用法示例。
在下文中一共展示了util.ForkAwareThreadLock方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_flags
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_flags(self):
import json, subprocess
# start child process using unusual flags
prog = ('from test.test_multiprocessing import TestFlags; ' +
'TestFlags.run_in_child()')
data = subprocess.check_output(
[sys.executable, '-E', '-B', '-O', '-c', prog])
child_flags, grandchild_flags = json.loads(data.decode('ascii'))
self.assertEqual(child_flags, grandchild_flags)
#
# Issue #17555: ForkAwareThreadLock
#
示例2: test_lock
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_lock(self):
r, w = multiprocessing.Pipe(False)
l = util.ForkAwareThreadLock()
old_size = len(util._afterfork_registry)
p = multiprocessing.Process(target=self.child, args=(5, w))
p.start()
new_size = r.recv()
p.join()
self.assertLessEqual(new_size, old_size)
#
# Issue #17097: EINTR should be ignored by recv(), send(), accept() etc
#
示例3: test_lock
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_lock(self):
r, w = multiprocessing.Pipe(False)
l = util.ForkAwareThreadLock()
old_size = len(util._afterfork_registry)
p = multiprocessing.Process(target=self.child, args=(5, w))
p.start()
new_size = r.recv()
p.join()
self.assertLessEqual(new_size, old_size)
#
#
#
示例4: test_noforkbomb
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_noforkbomb(self):
sm = multiprocessing.get_start_method()
name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py')
if sm != 'fork':
rc, out, err = test.support.script_helper.assert_python_failure(name, sm)
self.assertEqual(out, b'')
self.assertIn(b'RuntimeError', err)
else:
rc, out, err = test.support.script_helper.assert_python_ok(name, sm)
self.assertEqual(out.rstrip(), b'123')
self.assertEqual(err, b'')
#
# Issue #17555: ForkAwareThreadLock
#
示例5: test_lock
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_lock(self):
r, w = multiprocessing.Pipe(False)
l = util.ForkAwareThreadLock()
old_size = len(util._afterfork_registry)
p = multiprocessing.Process(target=self.child, args=(5, w))
p.start()
w.close()
new_size = r.recv()
p.join(timeout=5)
self.assertLessEqual(new_size, old_size)
#
# Check that non-forked child processes do not inherit unneeded fds/handles
#
示例6: test_noforkbomb
# 需要導入模塊: from multiprocessing import util [as 別名]
# 或者: from multiprocessing.util import ForkAwareThreadLock [as 別名]
def test_noforkbomb(self):
sm = multiprocessing.get_start_method()
name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py')
if sm != 'fork':
rc, out, err = test.script_helper.assert_python_failure(name, sm)
self.assertEqual(out, b'')
self.assertIn(b'RuntimeError', err)
else:
rc, out, err = test.script_helper.assert_python_ok(name, sm)
self.assertEqual(out.rstrip(), b'123')
self.assertEqual(err, b'')
#
# Issue #17555: ForkAwareThreadLock
#