summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2010-03-01 04:40:36 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2010-03-01 04:40:36 (GMT)
commitc21d0cb6cf1c32158a37772545fb71e730ab1323 (patch)
tree834c4f78660a6d3d0a92153bc7027439b386363d /Lib
parent56f1682a4462559b735c01c6cb8c06fd1afdc11b (diff)
downloadcpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.zip
cpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.tar.gz
cpython-c21d0cb6cf1c32158a37772545fb71e730ab1323.tar.bz2
Merged revisions 78527,78531 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78527 | gregory.p.smith | 2010-02-28 17:22:39 -0800 (Sun, 28 Feb 2010) | 4 lines Issue #7242: On Solaris 9 and earlier calling os.fork() from within a thread could raise an incorrect RuntimeError about not holding the import lock. The import lock is now reinitialized after fork. ........ r78531 | gregory.p.smith | 2010-02-28 18:31:33 -0800 (Sun, 28 Feb 2010) | 2 lines Fix for r78527. It left out updating forkpty. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_thread.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 8bbfdb1..8dd8d1e 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -4,6 +4,7 @@ import random
from test import test_support
import thread
import time
+import sys
from test import lock_tests
@@ -169,8 +170,47 @@ class LockTests(lock_tests.LockTests):
locktype = thread.allocate_lock
+class TestForkInThread(unittest.TestCase):
+ def setUp(self):
+ self.read_fd, self.write_fd = os.pipe()
+
+ def test_forkinthread(self):
+ if sys.platform.startswith('win'):
+ from test.test_support import TestSkipped
+ raise TestSkipped("This test is only appropriate for "
+ "POSIX-like systems.")
+ def thread1():
+ try:
+ pid = os.fork() # fork in a thread
+ except RuntimeError:
+ sys.exit(0) # exit the child
+
+ if pid == 0: # child
+ os.close(self.read_fd)
+ os.write(self.write_fd, "OK")
+ sys.exit(0)
+ else: # parent
+ os.close(self.write_fd)
+
+ thread.start_new_thread(thread1, ())
+ self.assertEqual(os.read(self.read_fd, 2), "OK",
+ "Unable to fork() in thread")
+
+ def tearDown(self):
+ try:
+ os.close(self.read_fd)
+ except OSError:
+ pass
+
+ try:
+ os.close(self.write_fd)
+ except OSError:
+ pass
+
+
def test_main():
- test_support.run_unittest(ThreadRunningTests, BarrierTest, LockTests)
+ test_support.run_unittest(ThreadRunningTests, BarrierTest, LockTests,
+ TestForkInThread)
if __name__ == "__main__":
test_main()