Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Threads and Forking (through ProcessPool and friends) #20

Open
Goobley opened this issue Jun 11, 2020 · 0 comments
Open

Document Threads and Forking (through ProcessPool and friends) #20

Goobley opened this issue Jun 11, 2020 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@Goobley
Copy link
Owner

Goobley commented Jun 11, 2020

If ctx.Nthreads > 1 on fork, then only main thread is copied, and none of the workers are cloned (as per the definition of fork(2)). If Nthreads is set to one and then increased in each child process then all is well. This happens with a Context in global state on creating a ProcessPoolExecutor.

Interestingly if ctx.Nthreads is left > 1, everything still runs (albeit only 1 thread per process). This is due to the way the task library works. It spawns N-1 threads, with the Nth being the main thread. When we call scheduler_join in the main thread, it jumps in and does the work (as if the other workers were busy).

This is all surprisingly close to "as one would/should expect" IMO, however it should be documented somewhere. For the most part if a job can use inter-process concurrency, it is unlikely to need the sub-process multi-threaded formal solutions that ctx.Nthreads exists for, so in most places ctx.Nthreads should be set to 1 before spawning. If multiple threads are needed in the children then there are two simple options off the top of my head: set ctx.Nthreads > 1 and the scheduler will happily spin up threads, or don't rely on the global state fork behaviour, and pass the context through the initialiser options available in ProcessPoolExecutor.

@Goobley Goobley added the documentation Improvements or additions to documentation label Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant