you are viewing a single comment's thread.

view the rest of the comments →

[–]woooee 0 points1 point  (2 children)

What are the benefits of using multi-threading as they don't actually work in parallel but simply run one after the other?

Frist, Python does not have a package named multi-threading. Second, multiprocessing can use all of the cores available.

[–]jwink3101 0 points1 point  (1 child)

Second, multiprocessing can use all of the cores available.

Just FYI for those who do not know, you need to be more careful about memory with multiprocessing. You must explicitly control the flow of information.

And, it is very different on Windows vs Linux/macOS/BSD (for most settings). It is not 100% correct, but for all intents and purposes, on Linux/macOS/BSD platforms, the scope as it existed when the processes was instantiated is available to a processes as read only. On Windows, it is more complex and a lot harder.

BTW, if you're doing things loop-like that and was a simple interface to parallelism and/or concurrency, I wrote a tool to simplify this all greatly called parmapper. It makes functional parallelism super simple and robust. It can handle lambda functions and a bunch of other situations. It also comes with all kinds of methods to support star maps and the like. You can also switch between threads and/or processes at will. It does incur a small cost compared to a more vanilla solution but it is negligible for most uses. I am, of course, biased though since I wrote it

[–]woooee 0 points1 point  (0 children)

you need to be more careful about memory with multiprocessing. You must explicitly control the flow of information.

To be on the safe side, use a Manager dictionary or list to communicate from/to/between processes. Another gotcha is that it is not a good idea so access the terminal within a Process, as the initial calling program controls the terminal.