On 06Nov2019 18:15, Rhodri James <rho...@kynesim.co.uk> wrote:
On 06/11/2019 16:02, Spencer Du wrote:
Why is importing modules in parallel bad?

To put it as simply as I can:

1. The import mechanism is complicated, even the bits that are user-visible. Fiddling with it has a high chance of going wrong.

2. Multi-threading is less complicated than import, but still requires a lot of careful thought. For example you've asserted that the modules you want to import simultaneously, but you also need to consider the import mechanism itself.

Put 1 and 2 together, and multi-threaded import sounds like a nightmare.

The import machinery has an internal lock. Parallel import statements via threads is, of itself, a safe thing to do. But if the module does significant work on things outside itself (eg doing work beyond defining local classes, constants etc) that work needs to be thread safe.

Provided the imported modules do only local work it should be safe.

Spencer's modules run unconditional stuff in addition to defining classes. That may cause trouble.

Cheers,
Cameron Simpson <c...@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to