File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ import test .support
2
+ from test .support .script_helper import assert_python_failure , assert_python_ok
3
+ import textwrap
4
+ import unittest
5
+
6
+
7
+
8
+
9
+ @test .support .cpython_only
10
+ class PySysGetAttrTest (unittest .TestCase ):
11
+
12
+
13
+ def test_changing_stdout_from_thread (self ):
14
+ # print should use strong reference to the stdout.
15
+ code = textwrap .dedent ('''
16
+ from contextlib import redirect_stdout
17
+ from io import StringIO
18
+ from threading import Thread
19
+ import time
20
+
21
+ class Foo:
22
+ def __repr__(self):
23
+ time.sleep(0.2)
24
+ return "Foo"
25
+
26
+
27
+ def thread1():
28
+ text = StringIO()
29
+ with redirect_stdout(text):
30
+ time.sleep(0.2)
31
+
32
+ def main():
33
+ t1 = Thread(target=thread1, args=())
34
+ t1.start()
35
+ time.sleep(0.1)
36
+ print(Foo())
37
+
38
+
39
+ if __name__ == "__main__":
40
+ main()
41
+ ''' )
42
+ rc , out , err = assert_python_ok ('-c' , code )
43
+ self .assertEqual (out , b"" )
44
+ self .assertEqual (err , b"" )
45
+
46
+ if __name__ == "__main__" :
47
+ unittest .main ()
You can’t perform that action at this time.
0 commit comments