[HN Gopher] Show HN: Bringing multithreading to Python's async e...
       ___________________________________________________________________
        
       Show HN: Bringing multithreading to Python's async event loop
        
       This project explores the integration of multithreading into the
       asyncio event loop in Python.  While this was initially built with
       enhancing CPU utilization for FastAPI servers in mind, the approach
       can be used with more general async programs too.  If you're
       interested in diving deeper into the details, I've written a blog
       post about it here: https://www.neilbotelho.com/blog/multithreaded-
       async.html
        
       Author : nbsande
       Score  : 18 points
       Date   : 2024-09-28 11:36 UTC (11 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | quotemstr wrote:
       | At that point, why bother with asyncio? What we really want is
       | something like Java virtual threads, something that doesn't have
       | a code color.
        
         | btown wrote:
         | gevent is exactly this! http://www.gevent.org/
         | 
         | My startup has been using it in production for years. It excels
         | at I/O bound workflows where you have highly concurrent real-
         | time usage of slow/unpredictable partner APIs. You just write
         | normal (non-async) Python code and the patched system internals
         | create yields to the event loop whenever you'd be waiting for
         | I/O, giving you essentially unlimited concurrency (as long as
         | all pending requests and their context fit in RAM).
         | 
         | https://github.com/gfmio/asyncio-gevent does exist to let you
         | use asyncio code in a gevent context, but it's far less battle-
         | tested and we've avoided using it so far.
        
         | drowsspa wrote:
         | Not for those of us stuck in Java 8... Is it stable already?
        
       | noident wrote:
       | > It got me wondering if it was actually possible to make
       | Python's async event loop work with multiple threads.
       | 
       | There is built-in support for this. Take a look at
       | loop.run_in_executor. You can await something scheduled in a
       | separate Thread/ProcessPoolExecutor.
       | 
       | Granted, this is different than making the async library end-to-
       | end multi-threaded as you seem to be trying to do, but it does
       | seem worth mentioning in this context. You _can_ have async and
       | multiple threads at the same time!
        
       ___________________________________________________________________
       (page generated 2024-09-28 23:01 UTC)