473,465 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with module variables / module deallocation . . .

Hello!

I got the next problem and didn't see any reference to the behaviour
that produces it, look:

If we have a module like:

--- mod.py --------------->8------
testvar2 = 15

def testfunc():
print testvar2
--- mod.py --------------->8------

And if we make:

--- test1.py --------------->8------
import sys
import mod

f = mod.testfunc
f()
del mod
del sys.modules['mod']
print 'after module dereferencing..'
f()
--- test1.py --------------->8------

or :

--- test2.py --------------->8------
import sys

def testloco():
import mod
return mod.testfunc

f = testloco()
f()
del sys.modules['mod']
print 'after module dereferencing..'
f()
--- test2.py --------------->8------

The last f() prints None.

YES, i know, that usually you are not
removing imports you made.

I'm getting that problem when using
pyhton's encodings/codecs modules.
C codecs module, keeps a reference to
a function in encodings pakage called
search_function, and after getting that
function, the module is auto deallocated
(except from sys.modules).
The application where we are using it,
embeeds python and after my module ends,
it "cleans up" sys.modules dictionary (not in
a clean way it seems), and I can't continue
using encodings later, because, when I
make 'something'.encode('some encoding'),
it searchs using that registered search function
that has problems accessing (invalid) data.

The problem is like this:

--- enc_test.py --------------->8------
import sys

def testencoding():
status = name in sys.modules.keys()
print 'is encodings loaded? ', status
return status

def get_sf():
import encodings
return encodings.search_function
f = get_sf()
del sys.modules['encodings'] #this line is articial, but..
print 'after module dereferencing..'
'bye'.encode('chau')
--- enc_test.py --------------->8------
One way to workaround this problem is that
codecs keeps a reference to encodings module.
There's no way that the function keeps a reference to
the module, to prevent the module's variable destruction?

Well. That's all.
david

PS: Is this the right mailing list for this kind of posts?
--
+ There is no dark side of the moon really. Matter of fact it's all dark.

Jul 18 '05 #1
0 1288

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

Similar topics

6
by: Uttam | last post by:
Hello, I am using the code from Chapter 17 specifically the code from the font frmListFonts in my application. I have taken care to copy all the relevant modules / class modules into the...
7
by: S. A. Hussain | last post by:
Where Global variables created in STACK or HEAP in C/C++? ve##tolimitsyahoocom, delete ##
1
by: shalin | last post by:
I am having a strange problem in my ASP.NET application. When multiple users access the web site, the changes done by a user gets reflected in another users session. I have some global...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
4
by: Galen Somerville | last post by:
I have a real timing problem. This involves getting data from a USB device via an ActiveX dll and drawing trace lines on the screen via a UserControl. The USB device sends six sets of pixel info...
18
by: welch.ryan | last post by:
Hi all, Having a problem with addressing large amounts of memory. I have a simple piece of code here that is meant to allocate a large piece of memory on a ppc64 machine. The code is: /*...
4
by: carl.dhalluin | last post by:
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\n print math.floor(y)\nf(3.14)" def execute(): exec mycode execute()
4
by: rshepard | last post by:
I'm stymied by what should be a simple Python task: accessing the value of a variable assigned in one module from within a second module. I wonder if someone here can help clarify my thinking. I've...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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.