(self)
| 41 | self.loop.run_forever() |
| 42 | |
| 43 | def terminate(self): |
| 44 | loop = getattr(self, "loop", None) |
| 45 | thread = getattr(self, "thread", None) |
| 46 | |
| 47 | if not loop: |
| 48 | return |
| 49 | |
| 50 | if loop.is_running(): |
| 51 | if thread and thread is threading.current_thread(): |
| 52 | loop.stop() |
| 53 | else: |
| 54 | loop.call_soon_threadsafe(loop.stop) |
| 55 | if thread: |
| 56 | thread.join() |
| 57 | elif thread and thread.is_alive() and thread is not threading.current_thread(): |
| 58 | thread.join() |
| 59 | |
| 60 | if not loop.is_closed(): |
| 61 | loop.close() |
| 62 | |
| 63 | with self.__class__._lock: |
| 64 | if self.thread_name in self.__class__._instances: |
| 65 | del self.__class__._instances[self.thread_name] |
| 66 | |
| 67 | self.loop = None |
| 68 | self.thread = None |
| 69 | |
| 70 | def run_coroutine(self, coro): |
| 71 | self._start() |
no test coverage detected