A
A
Alexander Bondarenko2021-10-21 11:36:39
Python
Alexander Bondarenko, 2021-10-21 11:36:39

Why does RuntimeError('Event loop is closed') occur?

I run two functions, there are no errors in them, everything works correctly, but then I get an error. Tell me how can I fix this?

def go():
    asyncio.run(main())
    asyncio.run(create_new_client())


threading.Thread(target=go).start()

Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000174EBB49C10>
Traceback (most recent call last):
  File "C:\Users\dev\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\dev\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\dev\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Users\dev\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bondarenko, 2021-10-21
@bond_1013

This solution helped me

async def tasks():
    await main()
    await create_new_client()

asyncio.get_event_loop().run_until_complete(tasks())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question