mod_wsgi icon indicating copy to clipboard operation
mod_wsgi copied to clipboard

Cannot use PyJWT/cryptography packages, failure at 'import jwt'...

Open petasis opened this issue 3 months ago • 1 comments

Doing import jwt fails with error: ImportError: PyO3 modules do not yet support subinterpreters, see https://github.com/PyO3/pyo3/issues/576.

Is there a fix for this import error?

The packages versions are:

$ python -m jwt.help
{
  "cryptography": {
    "version": "45.0.5"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.13.7"
  },
  "platform": {
    "release": "6.16.7-200.fc42.x86_64",
    "system": "Linux"
  },
  "pyjwt": {
    "version": "2.10.1"
  }
}

I have also reported the bug in the PyJWT package: https://github.com/jpadilla/pyjwt/issues/1092

petasis avatar Sep 15 '25 20:09 petasis

If not using mod_wsgi daemon mode already, for a start use that. Configure each separate WSGI application you may have to use a separate mod_wsgi daemon process group. At the same time, for each WSGI application force it to run in the main interpreter context of their respective mod_wsgi daemon process groups, rather than the default of using a sub interpreter context. For example:

WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP}

WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi process-group=example.com application-group=%{GLOBAL}

The key parameter here in respect of selecting the interpreter context is application-group, which should be set to %{GLOBAL}.

An alternate configuration you may see if look at documentation examples is:

WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP}

WSGIProcessGroup example.com
WSGIApplicationGroup %{GLOBAL}

WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi

That is, use WSGIProcessGroup and WSGIApplicationGroup directives.

Those directives apply to any WSGI application in that scope, eg., VirtualHost, so use of the option to WSGIScriptAlias may be better if have multiple WSGI applications.

GrahamDumpleton avatar Sep 15 '25 21:09 GrahamDumpleton