diff options
| author | bd <bdunahu@operationnull.com> | 2025-06-15 23:10:09 -0400 |
|---|---|---|
| committer | bd <bdunahu@operationnull.com> | 2025-06-15 23:10:09 -0400 |
| commit | 8844dceadcdeebf67d07656bf45d3ddada3e2b5b (patch) | |
| tree | 0d4e5204c8091cbf2ecb81437e5e1ab0f72511a1 /replacement_poll_selector.py | |
| parent | c21e4366fb64130d168150f0ed94293e699eb525 (diff) | |
Functional monkey-patched EpollSelector, good results
Diffstat (limited to 'replacement_poll_selector.py')
| -rw-r--r-- | replacement_poll_selector.py | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/replacement_poll_selector.py b/replacement_poll_selector.py deleted file mode 100644 index 0813a66..0000000 --- a/replacement_poll_selector.py +++ /dev/null @@ -1,41 +0,0 @@ -import selectors -import sys -import threading -import time -from typing import List, Optional, Tuple - -from mini_scalene import MiniScalene - - -@MiniScalene.shim -def replacement_poll_selector(mini_scalene: MiniScalene) -> None: - """ - A replacement for selectors.PollSelector that - periodically wakes up to accept signals - """ - - class ReplacementPollSelector(selectors.PollSelector): - def select( - self, timeout: Optional[float] = -1 - ) -> List[Tuple[selectors.SelectorKey, int]]: - tident = threading.get_ident() - start_time = time.perf_counter() - if not timeout or timeout < 0: - interval = sys.getswitchinterval() - else: - interval = min(timeout, sys.getswitchinterval()) - while True: - scalene.set_thread_sleeping(tident) - selected = super().select(interval) - scalene.reset_thread_sleeping(tident) - if selected or timeout == 0: - return selected - end_time = time.perf_counter() - if timeout and timeout != -1: - if end_time - start_time >= timeout: - return [] # None - - ReplacementPollSelector.__qualname__ = ( - "replacement_poll_selector.ReplacementPollSelector" - ) - selectors.PollSelector = ReplacementPollSelector # type: ignore |
