question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError "There is no current event loop in thread" if not on main Thread

See original GitHub issue

I’m getting an error using the basic example syntax. You mention a warning below on the README and if this is it, I apologize, but I’m not familiar enough with AsyncIO to connect the dots.

My code:

class GraphQLClient:

    transport = AIOHTTPTransport(url="https://fake.com/graphql")
    client = Client(transport=transport, fetch_schema_from_transport=True)

    def request(self, body):
        return self.client.execute(body)

client = GraphQLClient()
r = client.request(
    gql(
    """
    query getUserID {
      login( email_or_phone_or_username: "{username}" password:"{pw}") {
        user_id
      }
    }
    """
    )
 )

The error:

  File "/Users/michael/Documents/Projects/kpffl/sleeper.py", line 16, in request
    return self.client.execute(body)
  File "/Users/michael/Documents/Projects/kpffl/venv/lib/python3.8/site-packages/gql/client.py", line 113, in execute
    loop = asyncio.get_event_loop()
  File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-8'.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22

github_iconTop GitHub Comments

1reaction
redreceiptcommented, Aug 27, 2020

Tested and confirmed ✅

Actually found a much easier way on Google: pip install git+https://github.com/leszekhanusz/gql.git@fix_get_current_loop_in_new_thread

0reactions
leszekhanuszcommented, Oct 4, 2020

This is now fixed in version 3.0.0a2

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: There is no current event loop in thread in ...
If the target callable is not a coroutine function, it will be run in a worker thread (due to historical reasons), hence the...
Read more >
How to fix Python asyncio RuntimeError: There is no current ...
You are trying to run asyncio.get_event_loop() in some thread other than the main thread – however, asyncio only generates an event loop for...
Read more >
There is no current event loop in thread 'MainThread ... - GitHub
The webserver to launch and this error to not occur. Actual behavior. The error above before my code of the webserver even launches....
Read more >
Azure Function RuntimeError: There is no current event loop ...
Exception: RuntimeError: There is no current event loop in thread 'ThreadPoolExecutor-0_0'. I tried changing the Python version 3.8.10 to 3.9.11 ...
Read more >
runtimeerror: there is no current event loop in thread 'thread-1'.
You are running the check_time function as a separate thread. The asyncio event loop is thread-specific. So if you want to do asyncio-stuff...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found