RuntimeError "There is no current event loop in thread" if not on main Thread
See original GitHub issueI’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:
- Created 3 years ago
- Comments:22
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
This is now fixed in version 3.0.0a2