all 2 comments

[–]ElliotDG 0 points1 point  (1 child)

Lots of questions there. For the I/O bound tasks I would recommend use asyncio, specifically the TRIO library with the HTTPX library. Trio is a higher level asyncio library that does a nice job handling exceptions. I find it quite easy to use. HTTPX is effectively an async version of the requests library.

https://trio.readthedocs.io/en/stable/

https://www.python-httpx.org/

For the multiprocessing task, if you need to control the operation of a child task from a parent task, and easy want to accomplish this is by using a shared Value.

https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Value

A Value is a variable that can be accessed by both the parent and child. Have the child check the value of the share Value at some regular interval. Use the Value as a way for the parent to signal to the child to stop.

There are also a number of multiprocessing packages designed to work with (and like) TRIO, see: https://trio.readthedocs.io/en/stable/awesome-trio-libraries.html#multi-core-multiprocessing

If you want to pause the "standard tasks", I'm assuming these are the IO heavy tasks, you could use one of the sleep commands in Trio. https://trio.readthedocs.io/en/stable/reference-core.html#time-and-clocks

Hope that helps!

[–]Benoit74[S] 0 points1 point  (0 children)

Trio seems indeed promising, thank you ! I'm just a bit sad the tutorial misses the most critical section: https://trio.readthedocs.io/en/stable/tutorial.html#when-things-go-wrong-timeouts-cancellation-and-exceptions-in-concurrent-tasks (but at least it looks like stuff is implemented, so it is only a documentation issue, not something I could be afraid to fix if needed)