summaryrefslogtreecommitdiff
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-05-27 17:50:54 +0200
committerGitHub <noreply@github.com>2017-05-27 17:50:54 +0200
commit346cbd351ee0dd3ab9cb9f0e4cb625556707877e (patch)
tree8590c5fc85acf57750ecb8d07a407a3dbe233f85 /Lib/test/test_random.py
parentf931fd1c2ad969db72460d3ab41e3d1a4a62c371 (diff)
downloadcpython-git-346cbd351ee0dd3ab9cb9f0e4cb625556707877e.tar.gz
bpo-16500: Allow registering at-fork handlers (#1715)
* bpo-16500: Allow registering at-fork handlers * Address Serhiy's comments * Add doc for new C API * Add doc for new Python-facing function * Add NEWS entry + doc nit
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 45468c7ce4..f657b46b3a 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -1,6 +1,7 @@
import unittest
import unittest.mock
import random
+import os
import time
import pickle
import warnings
@@ -902,6 +903,24 @@ class TestModule(unittest.TestCase):
random.Random.__init__(self)
Subclass(newarg=1)
+ @unittest.skipUnless(hasattr(os, "fork"), "fork() required")
+ def test_after_fork(self):
+ # Test the global Random instance gets reseeded in child
+ r, w = os.pipe()
+ if os.fork() == 0:
+ try:
+ val = random.getrandbits(128)
+ with open(w, "w") as f:
+ f.write(str(val))
+ finally:
+ os._exit(0)
+ else:
+ os.close(w)
+ val = random.getrandbits(128)
+ with open(r, "r") as f:
+ child_val = eval(f.read())
+ self.assertNotEqual(val, child_val)
+
if __name__ == "__main__":
unittest.main()