diff options
author | Fred Drake <fdrake@acm.org> | 2000-04-10 15:36:39 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-04-10 15:36:39 (GMT) |
commit | 1a4b593dd67a9c9cbb1560f4c00ac9a63218aca7 (patch) | |
tree | f1cd9208ae7b1c66eb5452f5d437ab93a1e9286f /Lib | |
parent | 9706486b9fb8d25762095c855c3c2a976dcbf1d3 (diff) | |
download | cpython-1a4b593dd67a9c9cbb1560f4c00ac9a63218aca7.zip cpython-1a4b593dd67a9c9cbb1560f4c00ac9a63218aca7.tar.gz cpython-1a4b593dd67a9c9cbb1560f4c00ac9a63218aca7.tar.bz2 |
Use a constant to specify the number of child threads to create.
Instead of assuming that the number process ids of the threads is the
same as the process id of the controlling process, use a copy of the
dictionary and check for changes in the process ids of the threads
from the thread's process ids in the parent process. This makes the
test make more sense on systems which assign a new pid to each thread
(i.e., Linux).
This doesn't fix the other problems evident with this test on Linux.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_fork1.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index 361664e..c0e5b44 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -14,6 +14,8 @@ LONGSLEEP = 2 SHORTSLEEP = 0.5 +NUM_THREADS = 4 + alive = {} def f(id): @@ -25,14 +27,16 @@ def f(id): pass def main(): - for i in range(4): + for i in range(NUM_THREADS): thread.start_new(f, (i,)) time.sleep(LONGSLEEP) a = alive.keys() a.sort() - assert a == range(4) + assert a == range(NUM_THREADS) + + prefork_lives = alive.copy() cpid = os.fork() @@ -40,9 +44,8 @@ def main(): # Child time.sleep(LONGSLEEP) n = 0 - pid = os.getpid() for key in alive.keys(): - if alive[key] == pid: + if alive[key] != prefork_lives[key]: n = n+1 os._exit(n) else: |