Skip to content

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

Closed
@redreceipt

Description

@redreceipt

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/[email protected]/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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugAn issue or pull request relating to a bugtype: question or discussionIssue discussing or asking a question about gql

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions