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
Loading
Please register or sign in to comment