None module reference

Discussion in 'Python' started by Stefan Seefeld, May 22, 2005.

  1. hello,

    I'v run into a bug that I find hard to understand:

    In a python module of mine I import system modules
    ('sys', say) and then use them from within some functions.

    However, during program termination I'm calling
    one such function and the module reference ('sys')
    is 'None' !

    What does that mean ? Have those modules already
    been unloaded ? If so, why, given that my
    current module still references them ?

    Any help is highly appreciated,

    Stefan
     
    Stefan Seefeld, May 22, 2005
    #1
    1. Advertising

  2. Stefan Seefeld

    Kay Schluehr Guest

    Stefan Seefeld wrote:
    > hello,
    >
    > I'v run into a bug that I find hard to understand:
    >
    > In a python module of mine I import system modules
    > ('sys', say) and then use them from within some functions.
    >
    > However, during program termination I'm calling
    > one such function and the module reference ('sys')
    > is 'None' !


    Do You register Your function using atexit() ?

    This works perfectly fine and as expected for me. I would wonder if the
    interpreter was shut down and tries to execute a cleanup thereafter.

    Checkout following example code. You may also have a look at the
    /lib/atexit.py module see how it works.

    import atexit
    import sys
    def foo():
    print sys

    atexit.register(foo)

    Ciao,
    Kay
     
    Kay Schluehr, May 22, 2005
    #2
    1. Advertising

  3. Stefan Seefeld

    Peter Hansen Guest

    Stefan Seefeld wrote:
    > In a python module of mine I import system modules
    > ('sys', say) and then use them from within some functions.
    >
    > However, during program termination I'm calling
    > one such function and the module reference ('sys')
    > is 'None' !


    Are you running any daemon threads? This can generally happen when a
    daemon thread continues to access module globals during the interpreter
    shutdown sequence. At one stage all globals in all modules are rebound
    to None, and there's a chance some of your daemon thread code will
    execute just as this is occurring, resulting in that kind of error message.

    -Peter
     
    Peter Hansen, May 23, 2005
    #3
    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. alf
    Replies:
    9
    Views:
    420
  2. length power
    Replies:
    2
    Views:
    109
    Rustom Mody
    Apr 10, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    73
    Skip Montanaro
    Apr 10, 2014
  4. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    63
    Johannes Schneider
    Apr 10, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    71
    Terry Reedy
    Apr 10, 2014
Loading...

Share This Page