I stumbled on upon this anomaly in one of my programs and can't figure out why this is happening. I made a small test function that exhibits the same behavoir. It's like the local variables of my function are being saved after the function exits. The exclude_ids variable keeps growing. This same behavoir is apparent in IDLE, from cmd line, and when compiled. Tested on windows XP & 8. Python 2.7.4
>>> def is_running(exe_name, by_path=False, exclude_ids=[], exclude_this_process=False):
from os import getpid
from os.path import basename, abspath
if exclude_this_process:
exclude_ids.append(getpid())
print "exluded ids %s" % exclude_ids
return "-----------------"
>>> for x in xrange(10):
is_running("bob.exe", exclude_this_process=True)
exluded ids [5584]
'-----------------'
exluded ids [5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584]
'-----------------'
exluded ids [5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584, 5584]
'-----------------'
>>>
The list just keeps growing....