| 114 | break |
| 115 | |
| 116 | def _cleanup(self): |
| 117 | self._shutdown = True |
| 118 | if not self._thread: |
| 119 | return |
| 120 | |
| 121 | for conn in self._live_conns | self._new_conns | self._closed_conns: |
| 122 | conn.close() |
| 123 | for watcher in (conn._write_watcher, conn._read_watcher): |
| 124 | if watcher: |
| 125 | watcher.stop() |
| 126 | |
| 127 | self.notify() # wake the timer watcher |
| 128 | |
| 129 | # PYTHON-752 Thread might have just been created and not started |
| 130 | with self._lock_thread: |
| 131 | self._thread.join(timeout=1.0) |
| 132 | |
| 133 | if self._thread.is_alive(): |
| 134 | log.warning( |
| 135 | "Event loop thread could not be joined, so shutdown may not be clean. " |
| 136 | "Please call Cluster.shutdown() to avoid this.") |
| 137 | |
| 138 | log.debug("Event loop thread was joined") |
| 139 | |
| 140 | def add_timer(self, timer): |
| 141 | self._timers.add_timer(timer) |