Creating and destroying event loops should be pretty cheap. I suspect the biggest cost is creation of the self-pipe. (But if you really want to know, time it first.)
Multiple threads can each have their own independent event loop (accessible with get_event_loop() once created), so as long as they don't need to communicate that should be simple too. 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? On Sun, Jul 9, 2017 at 8:48 PM, Chris Jerdonek <chris.jerdo...@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@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)
_______________________________________________ Async-sig mailing list Async-sig@python.org https://mail.python.org/mailman/listinfo/async-sig Code of Conduct: https://www.python.org/psf/codeofconduct/