Newbie: Why Does This Work This Way...Global Variables And The Signal Module....
John Branthoover
jbranthoover at yahoo.com.NOSPAM
Thu Sep 13 18:12:14 EDT 2001
Hello All,
I have written a simple program to break out of a endless loop by
hitting control C, see below. This program works OK but I don't understand
why I have to define the global variable "Loop_Run" twice to get it to work.
I thought that you had only to define a global variable once at the
beginning of a program and that made it available to rest of the module.
Thanks in advance and have a great day!
#!/usr/local/bin/python
import signal
############################################################################
###
def signal_handler(signal, frame):
global Loop_Run
Loop_Run=0
print 'Signal Handler',Loop_Run
############################################################################
###
def Main():
global Loop_Run
Loop_Run = 1
signal.signal(signal.SIGINT, signal_handler)
while Loop_Run<>0:
print 'Loop is running because Loop_Run = ',Loop_Run
pass
print 'Loop is stopped because Loop_Run = ',Loop_Run
############################################################################
###
if __name__=='__main__':
Main()
More information about the Python-list
mailing list