From 3d05fe1069cf3a60bdf464140f8f79897b221382 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 24 Feb 2019 06:09:29 +0100 Subject: [PATCH] using Python process API --- test/sync_test.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/test/sync_test.py b/test/sync_test.py index 30a5ccb..ca5f16d 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -8,7 +8,7 @@ # this test is only running on POSIX systems -import os, pathlib, sys +import os, pathlib def test_for(path): @@ -59,19 +59,9 @@ def rmrf(path): EINTR = 4 -def waitpid(pid): - e = EINTR - while e == EINTR: - try: - pid, r = os.waitpid(pid, 0) - if r: - e = os.errno() - except ChildProcessError: - return - - if __name__ == "__main__": from optparse import OptionParser + from multiprocessing import Process optParser = OptionParser() optParser.add_option("-c", "--clean", action="store_true", dest="clean", @@ -88,14 +78,12 @@ if __name__ == "__main__": setup("Alice") setup("Barbara") - Alice = os.fork() - if Alice == 0: - test_for("Alice") - else: - Barbara = os.fork() - if Barbara == 0: - test_for("Barbara") - else: - waitpid(Alice) - waitpid(Barbara) + Alice = Process(target=test_for, args=("Alice",)) + Barbara = Process(target=test_for, args=("Barbara",)) + + Alice.start() + Barbara.start() + + Alice.join() + Barbara.join()