Python/C API access without GIL (crash)

Issue #2 new
created an issue

Build OS: Win 7

A Python plugin executes command event 'OpenDocumentWithDsi', for examples: {{{


self.executeCommandEvent('OpenDocumentWithDsi', dsi) }}} This leads to the crash.

The reason is that the SeranaApiCore.pyd wrapper releases Python's GIL before calling Serna. And then Serna creates a document and begins to initialize the plugins by calling pyplugin.dll. First use Python/C API without GIL leads to the crash (for example pyplugin.cxx!init_pyclass: _PyErr_Clear();)

The source code of SeranaApiCore.pyd is created automatically using SIP. You need to add an annotation /HoldGIL/ to the executeCommandEvent method definition in serna/pyapi/app/DocumentPlugin.sip:


!sip template

bool            executeCommandEvent(const SString&) const /HoldGIL/;
bool            executeCommandEvent(const SString&,
                                    const PropertyNode&) const /HoldGIL/;
bool            executeCommandEvent(const SString&,
                                    const PropertyNode&,
                                    const PropertyNode&) const /HoldGIL/;


Comments (3)

  1. teux reporter

    It might be better to comment out the argument "-g" in the file in package PyQt-x11-gpl-4.5.4 (line 1275).

        # There is an issue creating QObjects while the GIL is held causing
        # deadlocks in multi-threaded applications.  We don't fully understand this
        # yet so we make sure we avoid the problem by always releasing the GIL.

    In this case, Python will hold a global lock (GIL) for each call Serna API (use cases of Serna is not needed for multi-threaded Python). And PyQt works well with this setting.

  2. Log in to comment