Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 152800c

Browse files
committed
Improve test to run on macos and cover forkserver
1 parent df69347 commit 152800c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5421,6 +5421,24 @@ def test_preload_resources(self):
54215421
print(err)
54225422
self.fail("failed spawning forkserver or grandchild")
54235423

5424+
@unittest.skipIf(sys.platform == "win32", "Only Spawn on windows so no risk of mixing")
5425+
@only_run_in_spawn_testsuite("avoids redundant testing since we ignore the global context.")
5426+
def test_mixed_startmethod(self):
5427+
# Fork-based locks cannot be used with spawned process
5428+
for process_method in ["spawn", "forkserver"]:
5429+
queue = multiprocessing.get_context("fork").Queue()
5430+
p = multiprocessing.get_context(process_method).Process(target=close_queue, args=(queue,))
5431+
with self.assertRaisesRegex(RuntimeError, "A SemLock created in a fork"):
5432+
p.start()
5433+
5434+
# non-fork-based locks can be used with all other start methods
5435+
for queue_method in ["spawn", "forkserver"]:
5436+
for process_method in multiprocessing.get_all_start_methods():
5437+
queue = multiprocessing.get_context(queue_method).Queue()
5438+
p = multiprocessing.get_context(process_method).Process(target=close_queue, args=(queue,))
5439+
p.start()
5440+
p.join()
5441+
54245442

54255443
@unittest.skipIf(sys.platform == "win32",
54265444
"test semantics don't make sense on Windows")
@@ -6201,9 +6219,3 @@ class SemLock(_multiprocessing.SemLock):
62016219
name = f'test_semlock_subclass-{os.getpid()}'
62026220
s = SemLock(1, 0, 10, name, False)
62036221
_multiprocessing.sem_unlink(name)
6204-
6205-
def test_semlock_mixed_context(self):
6206-
queue = multiprocessing.get_context("fork").Queue()
6207-
p = multiprocessing.get_context("spawn").Process(target=close_queue, args=(queue,))
6208-
with self.assertRaisesRegex(RuntimeError, "A SemLock created in a fork"):
6209-
p.start()

0 commit comments

Comments
 (0)