|
|
|
|
|
by zahlman
392 days ago
|
|
Even when the 'spawn' strategy is used (default on Windows, and can be chosen explicitly on Linux), the overhead can largely be avoided. (Why choose it on Linux? Apparently forking can cause problems if you also use threads.) Python imports can be deferred (`import` is a statement, not a compiler or pre-processor directive), and child processes (regardless of the creation strategy) name the main module as `__mp_main__` rather than `__main__`, allowing the programmer to distinguish. (Being able to distinguish is of course necessary here, to avoid making a fork bomb - since the top-level code runs automatically and `if __name__ == '__main__':` is normally top-level code.) But also keep in mind that cleanup for a Python process also takes time, which is harder to trace. Refs: https://docs.python.org/3/library/multiprocessing.html#conte...
https://stackoverflow.com/questions/72497140 |
|
Sure, close TCP connections before you kill the whole thing. I couldn't care less about most objects, though.