[Async-sig] using asyncio in synchronous applications

Guido van Rossum guido at python.org
Mon Jul 10 10:46:06 EDT 2017


OK, then as long as close the connection and the loop properly it shouldn't
be a problem, even multi-threaded. (You basically lose all advantage of
async, but it seems you're fine with that.)

On Sun, Jul 9, 2017 at 9:07 PM, Chris Jerdonek <chris.jerdonek at gmail.com>
wrote:

> On Sun, Jul 9, 2017 at 9:00 PM, Guido van Rossum <guido at python.org> wrote:
> > But the big question is, what is that library doing for you? In the
> abstract
> > it is hard to give you a good answer. What library is it? What calls are
> you
> > making?
>
> It's the websockets library: https://github.com/aaugustin/websockets
>
> All I really need to do is occasionally connect briefly to a websocket
> server as a client from a synchronous app.
>
> Since I'm already using the library on the server-side, I thought I'd
> save myself the trouble of having to use two libraries and just use
> the same library on the client side as well.
>
> --Chris
>
>
>
>
> >
> > On Sun, Jul 9, 2017 at 8:48 PM, Chris Jerdonek <chris.jerdonek at gmail.com
> >
> > wrote:
> >>
> >> I have a two-part question.
> >>
> >> If my application is single-threaded and synchronous (e.g. a web app
> >> using Gunicorn with sync workers [1]), and occasionally I need to call
> >> functions in a library that requires an event loop, is there any
> >> downside to creating and closing the loop on-the-fly only when I call
> >> the function? In other words, is creating and destroying loops cheap?
> >>
> >> Second, if I were to switch to a multi-threaded model (e.g. Gunicorn
> >> with async workers), is my only option to start the loop at the
> >> beginning of the process, and use loop.call_soon_threadsafe()? Or can
> >> I do what I was asking about above and create and close loops
> >> on-the-fly in different threads? Is either approach much more
> >> efficient than the other?
> >>
> >> Thanks,
> >> --Chris
> >>
> >> [1] http://docs.gunicorn.org/en/latest/design.html#sync-workers
> >> _______________________________________________
> >> Async-sig mailing list
> >> Async-sig at python.org
> >> https://mail.python.org/mailman/listinfo/async-sig
> >> Code of Conduct: https://www.python.org/psf/codeofconduct/
> >
> >
> >
> >
> > --
> > --Guido van Rossum (python.org/~guido)
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20170710/5cd36510/attachment-0001.html>


More information about the Async-sig mailing list