[wsgi] Python interpreter initialization

Manlio Perillo manlio_perillo at libero.it
Mon Aug 20 14:15:26 MSD 2007


I need some help for the development of mod_wsgi.

Before using the Python C API for embedding Python code, the main 
interpreter must be initialized by calling

This function set a global context.

In the first version of the code, I'm initializing the interpreter in 
the init main configuration callback (and only here).

It is possible to customize the Python interpreter by setting some 
options before calling Py_Initialize.
These options are available as nginx commands in the main context only.

In the request handler I have added a call to the function 
Py_IsInitialized(), just to be sure.

I'm assuming that the main configuration is initialized in the core 
nginx process and that each one of the worker process simply inherit the 
Python interpreter context.

I'm right?

What happens on Windows (where fork is not available)?
Should I call Py_Initialize in the init process callback, too (calling 
Py_Initialize two times is a no op).

Thanks   Manlio Perillo

More information about the nginx mailing list