Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(159039)

Side by Side Diff: Lib/test/test_threading.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_sys.py ('k') | Lib/test/test_thread.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 Tests for the threading module. 2 Tests for the threading module.
3 """ 3 """
4 4
5 import test.support 5 import test.support
6 from test.support import verbose, strip_python_stderr, import_module, cpython_on ly 6 from test.support import verbose, strip_python_stderr, import_module, cpython_on ly
7 from test.support.script_helper import assert_python_ok, assert_python_failure 7 from test.support.script_helper import assert_python_ok, assert_python_failure
8 8
9 import random 9 import random
10 import re 10 import re
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 else: 818 else:
819 _, status = os.waitpid(pid, 0) 819 _, status = os.waitpid(pid, 0)
820 self.assertEqual(0, status) 820 self.assertEqual(0, status)
821 821
822 for t in threads: 822 for t in threads:
823 t.join() 823 t.join()
824 824
825 825
826 class SubinterpThreadingTests(BaseTestCase): 826 class SubinterpThreadingTests(BaseTestCase):
827 827
828 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't have os.pipe")
828 def test_threads_join(self): 829 def test_threads_join(self):
829 # Non-daemon threads should be joined at subinterpreter shutdown 830 # Non-daemon threads should be joined at subinterpreter shutdown
830 # (issue #18808) 831 # (issue #18808)
831 r, w = os.pipe() 832 r, w = os.pipe()
832 self.addCleanup(os.close, r) 833 self.addCleanup(os.close, r)
833 self.addCleanup(os.close, w) 834 self.addCleanup(os.close, w)
834 code = r"""if 1: 835 code = r"""if 1:
835 import os 836 import os
836 import threading 837 import threading
837 import time 838 import time
838 839
839 def f(): 840 def f():
840 # Sleep a bit so that the thread is still running when 841 # Sleep a bit so that the thread is still running when
841 # Py_EndInterpreter is called. 842 # Py_EndInterpreter is called.
842 time.sleep(0.05) 843 time.sleep(0.05)
843 os.write(%d, b"x") 844 os.write(%d, b"x")
844 threading.Thread(target=f).start() 845 threading.Thread(target=f).start()
845 """ % (w,) 846 """ % (w,)
846 ret = test.support.run_in_subinterp(code) 847 ret = test.support.run_in_subinterp(code)
847 self.assertEqual(ret, 0) 848 self.assertEqual(ret, 0)
848 # The thread was joined properly. 849 # The thread was joined properly.
849 self.assertEqual(os.read(r, 1), b"x") 850 self.assertEqual(os.read(r, 1), b"x")
850 851
852 @unittest.skipIf(sys.platform == 'ios', "iOS doesn't have os.pipe")
851 def test_threads_join_2(self): 853 def test_threads_join_2(self):
852 # Same as above, but a delay gets introduced after the thread's 854 # Same as above, but a delay gets introduced after the thread's
853 # Python code returned but before the thread state is deleted. 855 # Python code returned but before the thread state is deleted.
854 # To achieve this, we register a thread-local object which sleeps 856 # To achieve this, we register a thread-local object which sleeps
855 # a bit when deallocated. 857 # a bit when deallocated.
856 r, w = os.pipe() 858 r, w = os.pipe()
857 self.addCleanup(os.close, r) 859 self.addCleanup(os.close, r)
858 self.addCleanup(os.close, w) 860 self.addCleanup(os.close, w)
859 code = r"""if 1: 861 code = r"""if 1:
860 import os 862 import os
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 1103
1102 class MiscTestCase(unittest.TestCase): 1104 class MiscTestCase(unittest.TestCase):
1103 def test__all__(self): 1105 def test__all__(self):
1104 extra = {"ThreadError"} 1106 extra = {"ThreadError"}
1105 blacklist = {'currentThread', 'activeCount'} 1107 blacklist = {'currentThread', 'activeCount'}
1106 support.check__all__(self, threading, ('threading', '_thread'), 1108 support.check__all__(self, threading, ('threading', '_thread'),
1107 extra=extra, blacklist=blacklist) 1109 extra=extra, blacklist=blacklist)
1108 1110
1109 if __name__ == "__main__": 1111 if __name__ == "__main__":
1110 unittest.main() 1112 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_sys.py ('k') | Lib/test/test_thread.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+