Skip to content

Commit

Permalink
Merge branch 'master' into enable-flake8-pyi
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl authored Oct 25, 2023
2 parents c6aae4f + 9ec9d05 commit 9f4343d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ repos:
- id: mixed-line-ending
- id: check-case-conflict
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
rev: v0.1.1
hooks:
- id: ruff
types: [file]
Expand Down
4 changes: 0 additions & 4 deletions trio/_core/_tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2374,10 +2374,6 @@ async def crasher() -> NoReturn:
gc.garbage.clear()


@pytest.mark.xfail(
sys.version_info >= (3, 12),
reason="Waiting on https://github.com/python/cpython/issues/100964",
)
@pytest.mark.skipif(
sys.implementation.name != "cpython", reason="Only makes sense with refcounting GC"
)
Expand Down
28 changes: 26 additions & 2 deletions trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
import pytest
import sniffio

from .. import CapacityLimiter, Event, _core, fail_after, sleep, sleep_forever
from .. import (
CapacityLimiter,
Event,
_core,
fail_after,
move_on_after,
sleep,
sleep_forever,
)
from .._core._tests.test_ki import ki_self
from .._core._tests.tutil import buggy_pypy_asyncgens
from .._core._tests.tutil import buggy_pypy_asyncgens, slow
from .._threads import (
current_default_thread_limiter,
from_thread_check_cancelled,
Expand Down Expand Up @@ -1015,3 +1023,19 @@ async def test_from_thread_check_cancelled_raises_in_foreign_threads():
_core.start_thread_soon(from_thread_check_cancelled, lambda _: q.put(_))
with pytest.raises(RuntimeError):
q.get(timeout=1).unwrap()


@slow
async def test_reentry_doesnt_deadlock():
# Regression test for issue noticed in GH-2827
# The failure mode is to hang the whole test suite, unfortunately.
# XXX consider running this in a subprocess with a timeout, if it comes up again!

async def child() -> None:
while True:
await to_thread_run_sync(from_thread_run, sleep, 0, cancellable=False)

with move_on_after(2):
async with _core.open_nursery() as nursery:
for _ in range(4):
nursery.start_soon(child)
12 changes: 5 additions & 7 deletions trio/_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ async def run(self) -> None:
task = trio.lowlevel.current_task()
old_context = task.context
task.context = self.context.copy()
try:
await trio.lowlevel.cancel_shielded_checkpoint()
result = await outcome.acapture(self.unprotected_afn)
self.queue.put_nowait(result)
finally:
task.context = old_context
await trio.lowlevel.cancel_shielded_checkpoint()
await trio.lowlevel.cancel_shielded_checkpoint()
result = await outcome.acapture(self.unprotected_afn)
task.context = old_context
await trio.lowlevel.cancel_shielded_checkpoint()
self.queue.put_nowait(result)

async def run_system(self) -> None:
result = await outcome.acapture(self.unprotected_afn)
Expand Down

0 comments on commit 9f4343d

Please sign in to comment.