Safe to call Py_Initialize() frequently?

roschler robert.oschler at
Fri Mar 20 18:20:10 CET 2009

I've created a Python server that embeds Python 2.5 and runs Python
jobs.  I want to be able to completely "flush" the interpreter between
each job.  That means resetting all variables, stopping all user
created threads, and resetting the interpreter sys module path.  If it
does not cause memory leaks, slowdowns, or other problems I would like
to call Py_Initialize() before running each job.  I expect to run a
job about once a second.  Are there any known issues with doing this
or anything else that would make this a bad approach?

If it is a safe approach, do I have to pair each Py_Initialize() call
with a Py_Finalize() call?

If it is not a safe approach, is there another way to get what I want?


More information about the Python-list mailing list