I create 2 streams. In one, the tkinter window is drawn, in the second, asyncio establishes a connection to the server and receives commands from it. The second thread crashes after trying to create

loop = asyncio.get_event_loop() 

What could be the problem? Client = https://pastebin.com/EEBCfMNq

 C:\Users\Aleksey>py D:\Python\Сервер_Proj\new_client.py Exception in thread Thread-2: Traceback (most recent call last): File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "D:\Python\Сервер_Proj\new_client.py", line 85, in client loop = asyncio.get_event_loop() File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python36-32\lib\asyncio\events.py", line 678, in get_event_loop return get_event_loop_policy().get_event_loop() File "C:\Users\Aleksey\AppData\Local\Programs\Python\Python36-32\lib\asyncio\events.py", line 584, in get_event_loop % threading.current_thread().name) RuntimeError: There is no current event loop in thread 'Thread-2'. 

    1 answer 1

    From the documentation :

    It makes it possible to loop through the pathway. If you’re trying to do so, you’ll have to do it.

    In Russian, the first call to asyncio.get_event_loop() creates a new event loop only in the main thread, and throws an exception in any other one. So you have to create it yourself:

     loop = asyncio.new_event_loop() asyncio.set_event_loop(loop)