|
100 | 100 | 'get_ssl_adapter_class', |
101 | 101 | ) |
102 | 102 |
|
103 | | - |
104 | | -if sys.version_info[:2] >= (3, 13): |
105 | | - from queue import ( |
106 | | - Queue as QueueWithShutdown, |
107 | | - ShutDown as QueueShutDown, |
108 | | - ) |
109 | | -else: |
110 | | - |
111 | | - class QueueShutDown(Exception): |
112 | | - """Queue has been shut down.""" |
113 | | - |
114 | | - class QueueWithShutdown(queue.Queue): |
115 | | - """Add shutdown() similar to Python 3.13+ Queue.""" |
116 | | - |
117 | | - _queue_shut_down: bool = False |
118 | | - |
119 | | - def shutdown(self, immediate=False): |
120 | | - if immediate: |
121 | | - while True: |
122 | | - try: |
123 | | - self.get_nowait() |
124 | | - except queue.Empty: |
125 | | - break |
126 | | - self._queue_shut_down = True |
127 | | - |
128 | | - def get(self, *args, **kwargs): |
129 | | - if self._queue_shut_down: |
130 | | - raise QueueShutDown |
131 | | - return super().get(*args, **kwargs) |
132 | | - |
133 | | - |
134 | 103 | IS_WINDOWS = platform.system() == 'Windows' |
135 | 104 | """Flag indicating whether the app is running under Windows.""" |
136 | 105 |
|
@@ -1691,7 +1660,7 @@ def __init__( # pylint: disable=too-many-positional-arguments |
1691 | 1660 | self.reuse_port = reuse_port |
1692 | 1661 | self.clear_stats() |
1693 | 1662 |
|
1694 | | - self._unservicable_conns = QueueWithShutdown() |
| 1663 | + self._unservicable_conns = queue.Queue() |
1695 | 1664 |
|
1696 | 1665 | def clear_stats(self): |
1697 | 1666 | """Reset server stat counters..""" |
@@ -1904,9 +1873,8 @@ def prepare(self): # noqa: C901 # FIXME |
1904 | 1873 | def _serve_unservicable(self): |
1905 | 1874 | """Serve connections we can't handle a 503.""" |
1906 | 1875 | while self.ready: |
1907 | | - try: |
1908 | | - conn = self._unservicable_conns.get() |
1909 | | - except QueueShutDown: |
| 1876 | + conn = self._unservicable_conns.get() |
| 1877 | + if conn is _STOPPING_FOR_INTERRUPT: |
1910 | 1878 | return |
1911 | 1879 | request = HTTPRequest(self, conn) |
1912 | 1880 | try: |
@@ -2269,7 +2237,7 @@ def stop(self): # noqa: C901 # FIXME |
2269 | 2237 |
|
2270 | 2238 | # This tells the thread that handles unservicable connections to shut |
2271 | 2239 | # down: |
2272 | | - self._unservicable_conns.shutdown(immediate=True) |
| 2240 | + self._unservicable_conns.put(_STOPPING_FOR_INTERRUPT) |
2273 | 2241 |
|
2274 | 2242 | if self._start_time is not None: |
2275 | 2243 | self._run_time += time.time() - self._start_time |
|
0 commit comments