Skip to content
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

More tests for concurrency info #2746

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions test/container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2463,3 +2463,21 @@ def test_container_app_one_matching(servicer, event_loop):
def test_no_event_loop(servicer, event_loop):
ret = _run_container(servicer, "test.supports.functions", "get_running_loop")
assert _unwrap_exception(ret) == "RuntimeError('no running event loop')"


@skip_github_non_linux
def test_is_main_thread_sync(servicer, event_loop):
ret = _run_container(servicer, "test.supports.functions", "is_main_thread_sync")
assert _unwrap_scalar(ret) is True


@skip_github_non_linux
def test_is_main_thread_async(servicer, event_loop):
ret = _run_container(servicer, "test.supports.functions", "is_main_thread_async")
assert _unwrap_scalar(ret) is True


@skip_github_non_linux
def test_import_thread_is_main_thread(servicer, event_loop):
ret = _run_container(servicer, "test.supports.functions", "import_thread_is_main_thread")
assert _unwrap_scalar(ret) is True
19 changes: 19 additions & 0 deletions test/supports/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Modal Labs 2022
import asyncio
import contextlib
import threading
import time

from modal import (
Expand Down Expand Up @@ -718,3 +719,21 @@ def check_container_app():
@app.function()
def get_running_loop(x):
return asyncio.get_running_loop()


@app.function()
def is_main_thread_sync(x):
return threading.main_thread() == threading.current_thread()


@app.function()
async def is_main_thread_async(x):
return threading.main_thread() == threading.current_thread()


_import_thread_is_main_thread = threading.main_thread() == threading.current_thread()


@app.function()
def import_thread_is_main_thread(x):
return _import_thread_is_main_thread
Loading