Python API, objects, globals, and forking.

Discussion in 'Python' started by David M. Wilson, Apr 5, 2004.

  1. Hello,

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

    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?


    David.
     
    David M. Wilson, Apr 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Praveen, Tayal (IE10)
    Replies:
    0
    Views:
    399
    Praveen, Tayal (IE10)
    Mar 17, 2005
  2. Replies:
    1
    Views:
    411
    Gabriel Genellina
    Nov 8, 2006
  3. Globals or objects?

    , Feb 21, 2008, in forum: Python
    Replies:
    18
    Views:
    434
    Steven D'Aprano
    Feb 23, 2008
  4. John Connor
    Replies:
    0
    Views:
    255
    John Connor
    Apr 8, 2011
  5. Rick Johnson
    Replies:
    0
    Views:
    124
    Rick Johnson
    Nov 13, 2013
Loading...

Share This Page