Skip to content

Support sub-interpreters #545

Description

@mikeboers

From Gitter:

Newby question... is PyAV compatible with python sub-interpreters? According to the python docs https://docs.python.org/3/c-api/init.html using PyGILState_Ensure(), for example, is not compatible and I see this in the generated .c files inside #ifdef WITH_THREAD. I am trying to use PyAV inside a Django wsgi app and running into intermittent hang problems. Thanks in advance for your help.

I see that PyGILState_Ensure is called by __Pyx_RefNannySetupContext in every file. There are only 4 places that is called with acquire_gil being non-zero:

src/av/container/pyio.c: __Pyx_RefNannySetupContext("pyio_read", 1);
src/av/container/pyio.c: __Pyx_RefNannySetupContext("pyio_write", 1);
src/av/container/pyio.c: __Pyx_RefNannySetupContext("pyio_seek", 1);
src/av/logging.c: __Pyx_RefNannySetupContext("log_callback", 1);

So... if you don't use Python based IO, and disable the logging system, that should be clear.

This triggers it in each of the input/output containers, but I don't think control reaches it. Same with utils. This is another with gil in logging.

Okay... so there isn't a user-exposed way to disable the logging system adequately enough. We would have to restructure the Frame._init method just a bit to avoid the with gil, and add another method to logging to disable it entirely (or maybe check an envvar or something).

At that point, I don't think it will get called (if you avoid Python IO)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions