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.

[Question] Multiple workers with Sanic

See original GitHub issue

I have a Sanic app using python-socketio. The Websocket connection only works with app.run(workers=1); otherwise, Invalid session ... is raised.

Although I uses the AsyncRedisManager for the AsyncServer, the app still doesn’t seem to use redis to store the sessions:

app = Sanic(__name__)

mgr = socketio.AsyncRedisManager("redis://127.0.0.1:6379/0")
sio = socketio.AsyncServer(async_mode="sanic", cors_allowed_origins=[], client_manager=mgr)
sio.attach(app)

Is there a way for python-socketio to support multiple workers on Sanic ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelgrinbergcommented, Oct 27, 2019

@snguyenthanh Sanic does not do sticky session type load balancing when it runs multiple workers, so yes, you have to run multiple one worker Sanic apps, and put a proper load balancer that you can configure for sticky sessions.

0reactions
snguyenthanhcommented, Oct 28, 2019

I see. Thank you for the explanation.

I think I will just go with the multiple-1-worker-app approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Share a model object among multiple workers
I'm writing a websocket server in Sanic, which is to handle a frame sended from client, run an object-detection model and send the...
Read more >
Multiple Sanic workers with Motor - Stack Overflow
Sanic is not multi-threaded. And, forking is only used to setup the workers. If you instantiate motor using one of the server life...
Read more >
Deploying — Sanic 19.9.0 documentation
Sanic will automatically spin up multiple processes and route traffic between them. We recommend as many workers as you have available cores.
Read more >
Route Triggered State Update Across Python Sanic Workers
Say you want to trigger an update across all Sanic workers simply by ... Note that the application has multiple (2) workers instantiated....
Read more >
Rasa model loading twice (equal to number of Sanic workers)
Hi Rasa Team, I am trying to use RASA with 2 Sanic workers and ... I have a questions that is tensorflow or...
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