None module reference

S

Stefan Seefeld

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
 
K

Kay Schluehr

Stefan said:
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
 
P

Peter Hansen

Stefan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top