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

Some troubles using AsyncioExecutor and gunicorn #283

Open
WincerChan opened this issue Sep 15, 2020 · 0 comments
Open

Some troubles using AsyncioExecutor and gunicorn #283

WincerChan opened this issue Sep 15, 2020 · 0 comments

Comments

@WincerChan
Copy link

WincerChan commented Sep 15, 2020

Hello!

My web app has many api (not only have graphql, but also some rest-api), I am using graphql-core 2.3.2 provided AsyncioExecutor as Executor, and use Gunicorn as WSGI server in production.

The problem is when broswer send some requests concurrently , AsyncioExecutor will raise a error: RuntimeError: This event loop is already running.

After my debugging, I found that it was because AsyncioExecutor.wait_until_finished call loop.run_until_complete, then run_until_complete will check current loop if closed or running, and raise the error.

A worker of Gunicorn have some threads, those threads shares a event loop, and when a event loop is running, another concurrently request also call run_until_complete will raise RuntimeError, so they can't work well concurrently.

My solutions is create a event loop in a single thread, then call loop.run_forever(), and rewrite AsyncioExecutor.wait_until_finished as after:

def wait_until_finished(self):
    while self.futures:
        futures = self.futures
        self.futures = []
        # self.loop.run_until_complete(wait(futures))
        asyncio.run_coroutine_threadsafe(wait(futures), self.loop) # I added this line

it works, but this needs to edit the code of graphql-core package, is there a better solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant