Skip to content

RuntimeError: This event loop is already running  #30

@corzani

Description

@corzani

I am dealing with InquirerPy within an asyncio task something like:

import asyncio
from InquirerPy import inquirer

async def main():
    # Await... Something async...
    
    selected = inquirer.fuzzy(
        message="Select or Type a genre:",
        choices=['a', 'b', 'c']
    ).execute()

    print(selected)

if __name__ == '__main__':
    asyncio.run(main())

In any case I receive this kind of error:

    selected = await inquirer.fuzzy(
  File "/usr/local/lib/python3.9/site-packages/InquirerPy/base/simple.py", line 321, in execute
    result = self._run()
  File "/usr/local/lib/python3.9/site-packages/InquirerPy/base/complex.py", line 205, in _run
    return self.application.run()
  File "/usr/local/lib/python3.9/site-packages/prompt_toolkit/application/application.py", line 890, in run
    return loop.run_until_complete(
  File "/usr/local/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 618, in run_until_complete
    self._check_running()
  File "/usr/local/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 578, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
sys:1: RuntimeWarning: coroutine 'Application.run_async' was never awaited

Is there a better way to avoid this error instead of using nest-asyncio like libraries?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions