summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_thread.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_thread.py')
-rw-r--r--Lib/test/test_thread.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 413889a..a191e15 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -1,8 +1,8 @@
import os
import unittest
import random
-from test import test_support
-thread = test_support.import_module('thread')
+from test import support
+thread = support.import_module('_thread')
import time
import sys
import weakref
@@ -12,15 +12,13 @@ from test import lock_tests
NUMTASKS = 10
NUMTRIPS = 3
-
_print_mutex = thread.allocate_lock()
def verbose_print(arg):
"""Helper function for printing out debugging output."""
- if test_support.verbose:
+ if support.verbose:
with _print_mutex:
- print arg
-
+ print(arg)
class BasicThreadTest(unittest.TestCase):
@@ -143,7 +141,7 @@ class ThreadRunningTests(BasicThreadTest):
real_write(self, *args)
c = thread._count()
started = thread.allocate_lock()
- with test_support.captured_output("stderr") as stderr:
+ with support.captured_output("stderr") as stderr:
real_write = stderr.write
stderr.write = mywrite
started.acquire()
@@ -215,7 +213,6 @@ class BarrierTest(BasicThreadTest):
if finished:
self.done_mutex.release()
-
class LockTests(lock_tests.LockTests):
locktype = thread.allocate_lock
@@ -226,23 +223,25 @@ class TestForkInThread(unittest.TestCase):
@unittest.skipIf(sys.platform.startswith('win'),
"This test is only appropriate for POSIX-like systems.")
- @test_support.reap_threads
+ @support.reap_threads
def test_forkinthread(self):
def thread1():
try:
pid = os.fork() # fork in a thread
except RuntimeError:
- sys.exit(0) # exit the child
+ os._exit(1) # exit the child
if pid == 0: # child
- os.close(self.read_fd)
- os.write(self.write_fd, "OK")
- sys.exit(0)
+ try:
+ os.close(self.read_fd)
+ os.write(self.write_fd, b"OK")
+ finally:
+ os._exit(0)
else: # parent
os.close(self.write_fd)
thread.start_new_thread(thread1, ())
- self.assertEqual(os.read(self.read_fd, 2), "OK",
+ self.assertEqual(os.read(self.read_fd, 2), b"OK",
"Unable to fork() in thread")
def tearDown(self):
@@ -258,8 +257,8 @@ class TestForkInThread(unittest.TestCase):
def test_main():
- test_support.run_unittest(ThreadRunningTests, BarrierTest, LockTests,
- TestForkInThread)
+ support.run_unittest(ThreadRunningTests, BarrierTest, LockTests,
+ TestForkInThread)
if __name__ == "__main__":
test_main()