Skip to content

Commit

Permalink
Revert greenlet change; make sync loop close() actually terminate the…
Browse files Browse the repository at this point in the history
… thread; tests pass locally on 3.6 and 3.7
  • Loading branch information
oremanj committed Jan 6, 2020
1 parent 12c513f commit 6b1031a
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 138 deletions.
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"trio >= 0.12.0",
"async_generator >= 1.6",
"outcome",
"greenlet",
]
if sys.version_info < (3, 7):
install_requires.append("contextvars >= 2.1")
Expand Down
16 changes: 14 additions & 2 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,17 @@ def xfail(rel_id):
def skip(rel_id):
mark(pytest.mark.skip, rel_id)

base_sel_tests = "test_base_events.py::BaseEventLoopWithSelectorTests::"
xfail(base_sel_tests + "test_log_slow_callbacks")
xfail(
"test_base_events.py::BaseEventLoopWithSelectorTests::"
"test_log_slow_callbacks"
)

# This hangs, probably due to the thread shenanigans (it works
# fine with a greenlet-based sync loop)
skip("test_base_events.py::RunningLoopTests::test_running_loop_within_a_loop")

# trio-asyncio doesn't use a task factory
xfail(
"test_tasks.py::RunCoroutineThreadsafeTests::"
"test_run_coroutine_threadsafe_task_factory_exception"
)
13 changes: 13 additions & 0 deletions trio_asyncio/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,24 @@ def _new_run_get():
# Not Trio context
return _orig_run_get()

# Must override the non-underscore-prefixed get_running_loop() too,
# else will use the C-accelerated one which doesn't call the patched
# _get_running_loop()
def _new_run_get_or_throw():
result = _new_run_get()
if result is None:
raise RuntimeError("no running event loop")
return result

_aio_event._get_running_loop = _new_run_get
_aio_event.get_running_loop = _new_run_get_or_throw

#####

def _new_loop_get():
current_loop = _new_run_get()
if current_loop is not None:
return current_loop
return _trio_policy.get_event_loop()

def _new_loop_set(new_loop):
Expand Down
Loading

0 comments on commit 6b1031a

Please sign in to comment.