Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-128639: Don't assume one thread in subinterpreter finalization #128640

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add and fix tests.
  • Loading branch information
ZeroIntensity committed Jan 8, 2025
commit eea3ba95fc1bb34cf7df0164928b9d591efa87a1
56 changes: 54 additions & 2 deletions 56 Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,55 @@ def test_created_with_capi(self):
self.interp_exists(interpid))


def test_remaining_threads(self):
r_interp, w_interp = self.pipe()

FINISHED = b'F'

interp = interpreters.create()
interp.exec(f"""if True:
import os
import threading
import time

def task():
time.sleep(1)
ericsnowcurrently marked this conversation as resolved.
Show resolved Hide resolved
os.write({w_interp}, {FINISHED!r})

threads = [threading.Thread(target=task) for _ in range(3)]
for t in threads:
t.start()
""")
interp.close()

self.assertEqual(os.read(r_interp, 1), FINISHED)

def test_remaining_daemon_threads(self):
interp = _interpreters.create(
types.SimpleNamespace(
use_main_obmalloc=False,
allow_fork=False,
allow_exec=False,
allow_threads=True,
allow_daemon_threads=True,
check_multi_interp_extensions=True,
gil='own',
)
)
_interpreters.exec(interp, f"""if True:
import threading
import time

def task():
time.sleep(100)

threads = [threading.Thread(target=task, daemon=True) for _ in range(3)]
for t in threads:
t.start()
""")
_interpreters.destroy(interp)


class TestInterpreterPrepareMain(TestBase):

def test_empty(self):
Expand Down Expand Up @@ -756,7 +805,10 @@ def script():
spam.eggs()

interp = interpreters.create()
interp.exec(script)
try:
interp.exec(script)
finally:
interp.close()
""")

stdout, stderr = self.assert_python_failure(scriptfile)
Expand All @@ -765,7 +817,7 @@ def script():
# File "{interpreters.__file__}", line 179, in exec
self.assertEqual(stderr, dedent(f"""\
Traceback (most recent call last):
File "{scriptfile}", line 9, in <module>
File "{scriptfile}", line 10, in <module>
interp.exec(script)
~~~~~~~~~~~^^^^^^^^
{interpmod_line.strip()}
Expand Down
6 changes: 5 additions & 1 deletion 6 Lib/test/test_interpreters/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test_sys_path_0(self):
'sub': sys.path[0],
}}, indent=4), flush=True)
""")
interp.close()
ericsnowcurrently marked this conversation as resolved.
Show resolved Hide resolved
'''
# <tmp>/
# pkg/
Expand Down Expand Up @@ -172,7 +173,10 @@ def test_gh_109793(self):
argv = [sys.executable, '-c', '''if True:
from test.support import interpreters
interp = interpreters.create()
raise Exception
try:
raise Exception
finally:
interp.close()
''']
proc = subprocess.run(argv, capture_output=True, text=True)
self.assertIn('Traceback', proc.stderr)
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.