| 1340 | self._queue.put(_SHUTDOWNREQUEST) |
| 1341 | |
| 1342 | def stop(self, timeout=5): |
| 1343 | # Must shut down threads here so the code that calls |
| 1344 | # this method can know when all threads are stopped. |
| 1345 | for worker in self._threads: |
| 1346 | self._queue.put(_SHUTDOWNREQUEST) |
| 1347 | |
| 1348 | # Don't join currentThread (when stop is called inside a request). |
| 1349 | current = threading.currentThread() |
| 1350 | while self._threads: |
| 1351 | worker = self._threads.pop() |
| 1352 | if worker is not current and worker.isAlive(): |
| 1353 | try: |
| 1354 | if timeout is None or timeout < 0: |
| 1355 | worker.join() |
| 1356 | else: |
| 1357 | worker.join(timeout) |
| 1358 | if worker.isAlive(): |
| 1359 | # We exhausted the timeout. |
| 1360 | # Forcibly shut down the socket. |
| 1361 | c = worker.conn |
| 1362 | if c and not c.rfile.closed: |
| 1363 | if SSL and isinstance(c.socket, SSL.Connection): |
| 1364 | # pyOpenSSL.socket.shutdown takes no args |
| 1365 | c.socket.shutdown() |
| 1366 | else: |
| 1367 | c.socket.shutdown(socket.SHUT_RD) |
| 1368 | worker.join() |
| 1369 | except (AssertionError, |
| 1370 | # Ignore repeated Ctrl-C. |
| 1371 | # See http://www.cherrypy.org/ticket/691. |
| 1372 | KeyboardInterrupt), exc1: |
| 1373 | pass |
| 1374 | |
| 1375 | |
| 1376 | |