Should PyImport_ImportModule be threadsafe when importing from zipfiles?

Geoff Bache geoff.bache at gmail.com
Thu Feb 20 11:06:36 EST 2020


Hi Chris,

Yes, I've tried both of these things already. I can confirm there are
multiple calls, and that pre-importing the module fixes it. But
pre-importing it is not a solution in practice.

Regards,
Geoff

On Thu, Feb 20, 2020 at 4:45 PM Chris Angelico <rosuav at gmail.com> wrote:

> On Fri, Feb 21, 2020 at 2:37 AM Geoff Bache <geoff.bache at gmail.com> wrote:
> > When several threads execute this simultaneously I often get a stacktrace
> > saying some function near the end of module b is not defined, presumably
> > because the module has been imported part-initialised.
> > This only seems to happen when my Python modules are packaged in a zip
> > file, not when they are ordinary files on disk.
> >
> > I have observed this in both Python 3.7 and Python 3.8. Does anyone have
> > any insights or suggestions for how to debug this? It seems likely to be
> > hard to produce a reproducible test case.
>
> One easy way to probe the bug would be to pre-import the module before
> starting any secondary threads. If you ever get the problem under that
> pattern, then it's not a concurrency problem (IOW have fun figuring
> out what *is* the problem).
>
> Another thing to try: Slap a print call at the top and bottom of the
> module. See if you get multiple of them.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list