buggy python interpretter or am I missing something here?
me
noone at all.net
Sun Jan 26 22:42:58 EST 2014
I'm writing a linux daemon in python 2.x to process batches of GPS/GIS
data and I'm running into something that seems to break the expected
program flow in a REALLY BAD WAY.
Consider the attached template script and execute it with the -h option.
It is falling through to the except: clause even though try to manually
exit with sys.exit(0). However, if I insert a "raise" into the except
clause then the sys.exit(0) executes properly.
See the attached code and output from when I run it.
Not interested in work-arounds. I want to understand why it doesn't work
as expected.
Thanks!
TCdaemon.py ----
#! /usr/bin/python
import sys
#
------------------------------------------------------------------------------
defaultparams={ \
"basedir": "/process", \
"inpipe": "/tmp/TCdaemonIN", \
"maxjobs":8, \
"outpipe": "/tmp/TCdaemonOUT", \
"ZZZ": 0
}
#
------------------------------------------------------------------------------
def parse_args(a,d):
l=len(a)
idx=1
try:
while (idx<l):
if (a[idx]=="-#"):
idx=idx+1
d["maxjobs"]=int(a[idx])
elif (a[idx]=="-d"):
idx=idx+1
d["basedir"]=a[idx]
elif (a[idx]=="-h"):
print "help goes here"
sys.exit(0)
elif (a[idx]=="-i"):
idx=idx+1
d["inpipe"]=a[idx]
elif (a[idx]=="-o"):
idx=idx+1
d["outpipe"]=a[idx]
idx=idx+1
except:
# raise # -- WTF!!!??? required for -h to not fall through to
here?
print "%s: error in command line - %s"%(a[0],a[idx:])
sys.exit(1)
#
------------------------------------------------------------------------------
#
------------------------------------------------------------------------------
#
------------------------------------------------------------------------------
if (__name__=="__main__"):
print defaultparams
parse_args(sys.argv,defaultparams)
print defaultparams
output.txt ---
[@blackbox new]$ ./TCdaemon.py -h
{'ZZZ': 0, 'basedir': '/process', 'outpipe': '/tmp/TCdaemonOUT',
'maxjobs': 8, 'inpipe': '/tmp/TCdaemonIN'}
help goes here
./TCdaemon.py: error in command line - ['-h']
[@blackbox new]$ echo $?
1
[@blackbox new]$
[@blackbox new]$
[@blackbox new]$ # editing to add "raise" at line 40
[@blackbox new]$
[@blackbox new]$
[@blackbox new]$
[@blackbox new]$ ./TCdaemon.py -h
{'ZZZ': 0, 'basedir': '/process', 'outpipe': '/tmp/TCdaemonOUT',
'maxjobs': 8, 'inpipe': '/tmp/TCdaemonIN'}
help goes here
[@blackbox new]$ echo $?
0
[@blackbox new]$
More information about the Python-list
mailing list