[wsgi] Python interpreter initialization

Igor Sysoev is at rambler-co.ru
Mon Aug 20 14:45:33 MSD 2007

On Mon, Aug 20, 2007 at 12:15:26PM +0200, Manlio Perillo wrote:

> 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
>   Py_Initialize();
> 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.

Yes. init is called after whole http {} part has been processed.

> 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).

On Win32 each worker should read and process configuration from the start,
because they are not forks of master process.

Igor Sysoev

More information about the nginx mailing list