Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python API, objects, globals, and forking.

Thread Tools

Python API, objects, globals, and forking.

David M. Wilson
Posts: n/a

I have a C program embedding the Python interpreter, and loading a new
module like so:

exim_module = PyImport_ExecCodeModule("__exim__", compiled_module);

The program then forks a little while later, PyOS_AfterFork() gets
called, and everything appears to be honkey dory. However, given the
__exim__ module of:

foo = 1

def a():
print foo

def b():
print foo

When the program calls a(), "1" is printed as expected, but on the
second Python function call, "None" would be printed. Both calls occur
after the fork. Looking at globals(), all my user objects (foo, etc.)
are set to None, with the only object remaining untouched being
__builtins__. Interestingly, even the active function's reference in
globals() is set to None - suggesting the change occurs after my C
program does:

while (...)
root = PyObject_GetAttrString(last, pos);
/* succeeds in looking up the b() function object. */


result = PyObject_Call(callable, py_args, NULL);

The only other Python API calls I make in between these two are
PyTuple_New, PyTuple_SET_ITEM, PyObject_DECREF, and

Stuffing some user variables into __builtins__ and testing for them
later appears to work - so it looks like something is specifically
cleaning out the globals. Can someone shed any light on this?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Searching comp.lang.python/ (was: UTF-8) Python 0 03-10-2007 02:50 PM