[ python-Bugs-1707255 ] lost global variables in main memory intensive execution
SourceForge.net
noreply at sourceforge.net
Wed Apr 25 11:45:16 CEST 2007
Bugs item #1707255, was opened at 2007-04-25 11:45
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1707255&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Jordi Pujol Ahulló (jpahullo)
Assigned to: Nobody/Anonymous (nobody)
Summary: lost global variables in main memory intensive execution
Initial Comment:
Hello,
I was running a very main memory intensive program in my computer. I looked for similar bugs or troubles in the site and I didn't found any similar to this. I know that the use of global variables is not recommended by software engineering, but for special cases it is very fast to develop/test some ideas.
My problem statement is the following (very simplified and also attached):
########## BEGINNING OF CODE
#test for globals
counter_1 = 0
def modifierfunction():
global counter_1
#some code
counter_1 += 1
#some other code
def test():
for i in range(2):
global counter_1
counter_1 = 0
for j in range(10):
modifierfunction()
print "COUNTER_1:", counter_1
def test2():
global counter_1
for i in range(2):
counter_1 = 0
for j in range(10):
modifierfunction()
print "COUNTER_1:", counter_1
if __name__ == "__main__":
test()
test2()
########## END OF CODE
Globally speaking, it is a global variable, defined at the begining of the python file (counter_1), and it is modified in some functions within it (in this example, modifierfunction). At the end, it appear some tests that make what I need.
If you try to run this code, it will always show the expected values in the standard out. But, let me to show you my problem.
In the beginning, I have the global statement as in test2. But I found that it only take a corrent value for the first iteration. The others it has always a zero value. I didn't understand anything.
Then, some collegue suggested me to change the place of the global statement (as in test()), and then it worked correctly, as it was expected.
I repeat. The above example works fine. But when this same structure, but with my big problem, very main memory intensive, test2() didn't work correctly.
Thank you for your attention.
Regards,
Jordi
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1707255&group_id=5470
More information about the Python-bugs-list
mailing list