john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

concurrency threading terminate control c

from time import sleep

try:
    while True:
        print 'hi'
        sleep( 1 )
except KeyboardInterrupt as error:
    print 'quitting...'

print 'done'


threads are daemons but by having the "main thread" received the control + c

        try:
            for i in xrange( agent_pool.qsize() ):
                my_thread = ThreadUrl( agent_pool.get() , self.files_remaining , self.local_destination_path , self.local_files , retry_count_max )
                my_thread.daemon = True         # does not block the main program from exiting, must use a join() to block
                my_thread.start()                   # starts this thread

            self.files_remaining.join()     # wait on the que until task_done count is correct
        except KeyboardInterrupt:
            with self.files_remaining.mutex:
                self.files_remaining.clear()


(Also use the "poison pill" None method for "normal termination")
for i in xrange( agent_pool.qsize() )
    self.files_remaining.put( None )


In the THREAD

    while True
        if not self.files_remaining.get()
            self.cleanup()
            break

  • « oauth request token authorize access token
  • pyinstaller request sslerror manual cacert solution »

Published

Mar 8, 2013

Category

python

~107 words

Tags

  • c 95
  • concurrency 10
  • control 6
  • python 180
  • terminate 1
  • threading 3