agronholm / agronholm/anyio

Prevent socket selector thread from being suspended

Aperta
#869 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
Python
Stelle
2.5k
Fork
260
Merge medio
2g 8h
PR unite (30g)
19

Descrizione

### Things to check first

- [x] I have searched the existing issues and didn't find my feature already requested there

### Feature description

When using [debugpy](https://github.com/microsoft/debugpy) to debug a Python program, one might want the AnyIO socket selector thread (on Windows with the ProactorEventLoop) to keep running when the program is stopped on a breakpoint.

### Use case

It's the case in ipykernel where I currently have to write something like [that](https://github.com/ipython/ipykernel/blob/b55589244926cbc88cecddd419094b3beaa0b188/ipykernel/kernelapp.py#L712-L719):
```py
if backend == "asyncio" and sys.platform == "win32":
import asyncio

policy = asyncio.get_event_loop_policy()
if policy.__class__.__name__ == "WindowsProactorEventLoopPolicy":
from anyio._core._asyncio_selector_thread import get_selector
selector = get_selector()
selector._thread.pydev_do_not_trace = True
```
The key part is `selector._thread.pydev_do_not_trace = True`, that ensures the thread is not suspended.
Do you think there should be a better API for that, or should it even be done by default?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.