0

I've developed a Flask app where I use ThreadPoolExecutor(max_workers=4) in my code. I use this pool of threads when I send API requests to 3rd parties, in order to work in an asynchronous fashion.

I deliver my app in production using Gunicron with 5 workers and came to the conclusion I need to use Gevent or asyncio to be able to handle more requests concurrently.

My question is, can Gevent or asyncio work with a code where I already open I/O tasks in new threads? Or I should stop opening new threads for any task and simply migrate to Gevent/ asyncio?

IdoS
  • 482
  • 1
  • 10
  • 18
  • I find questions à la _"will X work in my use case"_ not very productive. Why don't you **just try it** instead of asking? Then, if you encounter some specific problem, you can create a reproducible mini-example to demonstrate the problem and ask for a solution. Can you work both with multiple threads and `asyncio` in the same application? In general, yes. Does that answer help you? Probably not. – Daniil Fajnberg Jun 06 '23 at 11:04
  • Gevent supports monkey patching the standard library - including threads. More info here: http://www.gevent.org/api/gevent.monkey.html#gevent.monkey.patch_thread Bottom line, you should be able to adopt Gevent with monkey patching without changing your implementation using ThreadPoolExecutor(). – David K. Hess Jun 08 '23 at 18:16

0 Answers0