473,769 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

None module reference

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
Jul 19 '05 #1
2 1380

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

Jul 19 '05 #2
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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2082
by: Grant D. Watson | last post by:
If this has been answered before, or if my terminology is off, please bear with me; my Python experience is limited to use in one class and to personal projects. I'd like to do something rather silly: I'd like to run a particular piece of code from a given module every time that the module is imported, and not just at the time that the module is originally loaded. So, every time a module says import foo or something analogous, I want...
15
1865
by: Josef Meile | last post by:
Hi, Textually from the highlights of python 2.4: "Assigning to None - the compiler now treats assigning to None as a SyntaxError." I think in general assignments to built-in types, functions, and variables should be also forbiden. It's a common mistake to do things like this:
4
8447
by: Brad Tilley | last post by:
When memory usage is a concern, is it better to do: from X import Y or import X Also, is there a way to load and unload modules as they are needed. I have some scripts that sleep for extended periods during a while loop
15
2133
by: Ron Adam | last post by:
Does anyone have suggestions on how to improve this further? Cheers, Ron_Adam def getobjs(object, dlist=, lvl=0, maxlevel=1): """ Retrieve a list of sub objects from an object. """
17
1676
by: Jan Danielsson | last post by:
Hello all, I recently started using Python, and I must say I like it. Both the language and libraries available for it. Background: I have written an application which I use to keep track of my personal economy. I wrote it in Java because I wanted to learn the language for a course in programming at my university. Now that I have acquired an interrest in Python I was thinking about porting my program to Python.
4
1613
by: Ron | last post by:
Hello, I have added a Namespace to my vb.net project. The namespace is the name of the project. Then I start the project from Sub Main Module1 Sub Main() Application.Run(New MyProj.Form1) End Sub
17
18430
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply provide the form name as a prefix to the object within the form and that would do it (kind of like providing a fully qualified path name to a
9
2044
by: alf | last post by:
Hi, I have a reference to certain objects. What is the most pythonic way to test for valid reference: if obj: if None!=obs: if obj is not None:
6
1116
by: Steven D'Aprano | last post by:
I have a function that needs a reference to the module object it is defined in. (For the reason why, if you care, see the thread "doctest not seeing any of my doc tests" from a week ago.) I know of two ways to deal with this problem, both of which feel unsatisfactory to me. Assume the name of the module is "Mod", then I can do either of these: def foo(): import Mod process(Mod)
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.