| 34 | |
| 35 | |
| 36 | class AnyThreadEventLoopPolicy(BaseThreadPolicy): |
| 37 | def get_event_loop(self) -> asyncio.AbstractEventLoop: |
| 38 | try: |
| 39 | return super().get_event_loop() |
| 40 | except (RuntimeError, AssertionError): |
| 41 | loop = self.new_event_loop() |
| 42 | self.set_event_loop(loop) |
| 43 | return loop |
| 44 | |
| 45 | asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) |
| 46 |