# Asyncio in a nogil world

**URL:** <https://discuss.python.org/t/asyncio-in-a-nogil-world/30694>\
**Category:** Async-SIG\
**Created:** [July 31, 2023, 2:37pm UTC](https://discuss.python.org/t/asyncio-in-a-nogil-world/30694 "2023-07-31T14:37:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Tinche](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tinche/32/12507_2.png) [@Tinche](https://discuss.python.org/u/Tinche)\
**Post date:** [July 31, 2023, 3:24pm UTC](https://discuss.python.org/t/asyncio-in-a-nogil-world/30694/3 "2023-07-31T15:24:44Z")

</div>

> [@Rosuav](#):
>
> Threads have overhead.

Yeah, threads + sync IO are not the best. You’d also lose asyncio cancellation semantics which are great. I’m personally also not enthused by this approach, but folks are using it I guess.

> [@Rosuav](#):
>
> I personally think that the “event loop that can multiplex active tasks” approach is more clunky than simply having independent event loops on the separate threads, although I’m open to examples showing otherwise.

Your tasks will presumably be using a bunch of libraries (like aiohttp, sqlalchemy, httpx, aioredis…) to do their work. All of these libraries maintain connections pools internally. These connection pools are bound to an event loop. So if you have N independent event loops, you’ll need a connection pool per loop. While it’s not the end of the world, it’s still pretty bad for a bunch of reasons. For example, you risk having a connection pool starved in one thread while an identical connection pool has available connections in another thread. Likewise, (depending on your library) you risk hogging database resources with unnecessary idle connections. All of this would be alleviated with a pool that’s a little bigger but shared between threads.

That said, I mentioned I think none of these libraries are “nogil-asyncio” safe today. But they could be adapted, if that’s what we decide on.

---

_[View the full topic](https://discuss.python.org/t/asyncio-in-a-nogil-world/30694)._
