| 71 | |
| 72 | |
| 73 | def _atexit_callback() -> None: |
| 74 | for loop in _selector_loops: |
| 75 | with loop._select_cond: |
| 76 | loop._closing_selector = True |
| 77 | loop._select_cond.notify() |
| 78 | try: |
| 79 | loop._waker_w.send(b"a") |
| 80 | except BlockingIOError: |
| 81 | pass |
| 82 | if loop._thread is not None: |
| 83 | # If we don't join our (daemon) thread here, we may get a deadlock |
| 84 | # during interpreter shutdown. I don't really understand why. This |
| 85 | # deadlock happens every time in CI (both travis and appveyor) but |
| 86 | # I've never been able to reproduce locally. |
| 87 | loop._thread.join() |
| 88 | _selector_loops.clear() |
| 89 | |
| 90 | |
| 91 | atexit.register(_atexit_callback) |