Skip to content
Unverified Commit accc97f1 authored by Pierre Langlois's avatar Pierre Langlois Committed by GitHub
Browse files

Ensure the `threaded_tests` module can be imported safely (#90)

On MacOS, running `multiprocessing.Manager()` spawns a new process. This
means it's not OK to run this in the global namespace, as that runs
while modules are being resolved, before main. The multiprocessing
guidelines [0], under "Safe importing of main module", indicate that
multiprocessing operations may have side-effects and mustn't run at that
point.

This turns the `Test.manager` global object into a local variable. The
manager's job is to handle shared state between processes and so its
lifetime is tied to the shared data. That data is then tied to the
`TestQueue` instance which runs tests in parallel and collects results.

So we can wrap the parallel test queue runner with a
`multiprocess.Manager()` context:

    def Run(self, ...):
      with multiprocessing.Manager() as manager:
        # Run tests in parallel with manager

[0]: https://docs.python.org/3/library/multiprocessing.html#multiprocessing-programming
parent ef2f4d15
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment