4 ms·
Looks very well designed. As someone new to asynchronous programming in python, I have been using asyncio.to_thread in a task. Although the best way to manage t
by therediterator 2y ago
Looks very well designed. As someone new to asynchronous programming in python, I have been using asyncio.to_thread in a task. Although the best way to manage things is to use a thread pool executor
- alexrustic 2y agoThanks for your comment ! When you are doing parallelism, don't forget to protect the 'entry point' of the program by using "if __name__ == '__main__'", and also avoid the __main__.py file [1] # this file isn't `__main__.py` ! from asyncpal import ProcessPool def square(x): return x**2 if __name__ == "__main__": # very important ! with ProcessPool(4) as pool: numbers = range(1000) # note that 'map_all' isn't lazy iterator = pool.map(square, numbers) # map is lazy result = tuple(iterator) assert result == tuple(map(square, numbers)) [1] https://discuss.python.org/t/why-does-multiprocessing-not-work-properly-in-main-py/20822 https://discuss.python.org/t/why-does-multiprocessing-not-wo...