kill thread

Mathieu Prevot mathieu.prevot at gmail.com
Thu Aug 7 15:56:14 EDT 2008


Hi,

I have a threading.Thread class with a "for i in range(1,50)" loop
within. When it runs and I do ^C, I have the error [1] as many as
loops. I would like to catch this exception (and if possible do some
cleanup like in C pthreads) so the program finishes cleanly. Where and
how can I do this ? in __run__ ? __init__ ? a try/except stuff ?

Thanks,
Mathieu

[1]:
^CException in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/threading.py",
line 486, in __bootstrap_inner
    self.run()
  File "./youfetch.py", line 148, in run
    self.getids()
  File "./youfetch.py", line 145, in getids
    self.ids.append(self.getidsatpage(i))
  File "./youfetch.py", line 138, in getidsatpage
    self.child = subprocess.Popen(cmd.split(),stdout=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py",
line 594, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py",
line 1011, in _execute_child
    self.pid = os.fork()
KeyboardInterrupt



More information about the Python-list mailing list