8000 gh-130163: Fix usage of borrow references from _PySys_GetAttr by sergey-miryanov · Pull Request #130282 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130163: Fix usage of borrow references from _PySys_GetAttr #130282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Next Next commit
Add test for changing stdout from thread
  • Loading branch information
sergey-miryanov committed Feb 18, 2025
commit f5b64f6b665edd39c7cfd951b24b1058007408d6
47 changes: 47 additions & 0 deletions Lib/test/test_sys_getattr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import test.support
from test.support.script_helper import assert_python_failure, assert_python_ok
import textwrap
import unittest




@test.support.cpython_only
class PySysGetAttrTest(unittest.TestCase):


def test_changing_stdout_from_thread(self):
# print should use strong reference to the stdout.
code = textwrap.dedent('''
from contextlib import redirect_stdout
from io import StringIO
from threading import Thread
import time

class Foo:
def __repr__(self):
time.sleep(0.2)
return "Foo"


def thread1():
text = StringIO()
with redirect_stdout(text):
time.sleep(0.2)

def main():
t1 = Thread(target=thread1, args=())
t1.start()
time.sleep(0.1)
print(Foo())


if __name__ == "__main__":
main()
''')
rc, out, err = assert_python_ok('-c', code)
self.assertEqual(out, b"")
self.assertEqual(err, b"")

if __name__ == "__main__":
unittest.main()
Loading
0