Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Potential issue] RuntimeError: Event loop is closed when not using extra loops #2

Open
Aluerie opened this issue Nov 27, 2023 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@Aluerie
Copy link
Owner

Aluerie commented Nov 27, 2023

PROBLEM

If we want to use a single event loop over the whole execution then it won't be possible because lcu-driver library closes current event loop by default. Maybe, I don't understand something. But with just

def __init(self, ...):
    super().__init__()
    ...

in AluConnector class it will NOT work on multiple GUI button presses because the first loop is already dead.

The error will be

14:53:41 27/11 | INFO    | connect                        | Icon with Id=25 was set correctly.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Me\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "d:\LAPTOP\HextechButEfficient\venv\Lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
    self._command()
  File "D:\LAPTOP\HextechButEfficient\gui\elements.py", line 89, in update_console_box
    connector.start()
  File "d:\LAPTOP\HextechButEfficient\venv\Lib\site-packages\lcu_driver\connector.py", line 70, in start
    wrapper()
  File "d:\LAPTOP\HextechButEfficient\venv\Lib\site-packages\lcu_driver\connector.py", line 64, in wrapper
    self.loop.run_until_complete(connection.init())
  File "C:\Users\Me\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 628, in run_until_complete
    self._check_closed()
  File "C:\Users\Me\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

CURRENT SOLUTION

One possible solution to this is to register a new loop on each GUI button press. But is it a good practice? I kinda doubt. If anybody knows better - please hit me up.

new_loop = asyncio.new_event_loop()
super().__init__(loop=new_loop)

LINKS

Even tho these are about websocket issue, where the loop won't close (which is the opposite problem lol) because of oversight design; but still they might change the structure of event loops usage after solving those.

@Aluerie Aluerie changed the title [Potential issue] RuntimeError: Event loop is closed without using opening extra loops [Potential issue] RuntimeError: Event loop is closed when not using extra loops Nov 27, 2023
@Aluerie Aluerie added enhancement New feature or request question Further information is requested labels Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant