Coder Social home page Coder Social logo

Comments (5)

1st1 avatar 1st1 commented on May 26, 2024 3

I am aware the correct way to approach this situation is wsgi, which is where we're headed. However I'm curious if it's possible directly.

I don't think anything async should ever use WSGI stack. So it's something you can try, but it's definitely not "the correct" way.

I know that Sanic uses uvloop by default, so my question is: have you tried both asyncio and asyncio+uvloop with reuse_port=True?

Also, there are other ways how you can share a socket between multiple processes. One way is to manually create a socket in the main process, bind it, set it to be inheritable, and then fork (either manually, or using multiprocessing). Then, in subprocesses, you can start asyncio event loop and call loop.create_server(sock=inherited_sock).

from asyncio.

r0fls avatar r0fls commented on May 26, 2024

I am aware the correct way to approach this situation is wsgi, which is where we're headed. However I'm curious if it's possible directly.

from asyncio.

gvanrossum avatar gvanrossum commented on May 26, 2024

Note: I've never heard of Sanic and haven't looked at its code. But maybe this comment from the referenced thread is relevant?

I wonder if the issue is that different process can't share same uvloop.

How does Sanic create worker processes? If it just forks and then runs the same code in each, especially if the loop has already been started, that is indeed a problem. Is there a way create the workers first and then create a loop in each one?

from asyncio.

r0fls avatar r0fls commented on May 26, 2024

If it just forks and then runs the same code in each, especially if the loop has already been started, that is indeed a problem. Is there a way create the workers first and then create a loop in each one?

This does look like what is happening...

have you tried both asyncio and asyncio+uvloop with reuse_port=True

Yes, I've tried removing uvloop and using only asyncio, which is why I opened the issue here.

from asyncio.

r0fls avatar r0fls commented on May 26, 2024

I got this working with the method suggested by @1st1, thank you both.

from asyncio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.