python - Why do threads continue to run after application has exited? -


the following python application spans few threads, spawns new process of , exits:

from pprint import pprint    import os import random import signal import sys  import threading import time   class name(object):     def __init__(self, name):         self.name = name   class callthreads(threading.thread):     def __init__(self, target, *args):         self.target = target         self.args = args         threading.thread.__init__(self)      def run (self):         self.target(*self.args)   def main(args):     print("hello, world!")     letter = random.choice(['a', 'b', 'c', 'd', 'e', 'f'])     count = 0      while count<3:         count += 1         name = name(letter+str(count))         t = callthreads(provider_query, name)         t.daemon = true         t.start()         time.sleep(3)         print("------------")      print("time die!")     os.system('python restart.py')     sys.exit(0)   def provider_query(name):     while name.name!='':         print(name.name)         time.sleep(1)   def signal_handler(signal, frame):     sys.exit()   if __name__ == '__main__':     signal.signal(signal.sigint, signal_handler)     main(sys.argv) 

i expect after process exits, threads associated cease function. however, running above program on kubuntu linux shows me processes continue run, after application has exited , new process has spawned. see threads continue output stdout. if comment out daemon line, processes continue run.

why processes continue run after sys.exit() has been called, , how can them stop? issue occurs on python 2.7 , python 3.2 in kubuntu linux 12.10.

you never made sys.exit() call. os.system('python restart.py') blocks until restart.py completes - child restart.py blocks on yet child restart.py, , etc... until blow process table. should see restart.py in process table every 9 seconds.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -