def wait_for_idle(self, workers, queue): """ Wait until fetch queue is empty and handle user interrupt """ while not self.kill_received and not queue.empty(): try: sleep(0.1) except KeyboardInterrupt: try: stats.output_stats() sleep(1) except KeyboardInterrupt: textutils.output_info('Keyboard Interrupt Received, cleaning up threads') # Clean reference to sockets database.connection_pool = None self.kill_received = True # Kill remaining workers but don't join the queue (we want to abort:)) for worker in workers: worker.kill_received = True if worker is not None and worker.isAlive(): worker.join(1) # Kill the soft sys.exit() # Make sure everything is done before sending control back to application textutils.output_debug("Threads: joining queue of size: " + str(queue.qsize())) queue.join() textutils.output_debug("Threads: join done") for worker in workers: worker.kill_received = True worker.join()
def wait_for_idle(self, workers, queue): """ Wait until fetch queue is empty and handle user interrupt """ while not self.kill_received and not queue.empty(): try: sleep(0.1) except KeyboardInterrupt: try: stats.output_stats() sleep(1) except KeyboardInterrupt: textutils.output_info( 'Keyboard Interrupt Received, cleaning up threads') self.kill_received = True # Kill remaining workers but don't join the queue (we want to abort:)) for worker in workers: worker.kill_received = True if worker is not None and worker.isAlive(): worker.join(1) # Kill the soft sys.exit() # Make sure everything is done before sending control back to application textutils.output_debug("Threads: joining queue of size: " + str(queue.qsize())) queue.join() textutils.output_debug("Threads: join done") for worker in workers: worker.kill_received = True worker.join()
def wait_for_idle(self, workers, queue): """ Wait until fetch queue is empty and handle user interrupt """ while not database.kill_received and not queue.empty(): try: sleep(0.1) except KeyboardInterrupt: try: stats.output_stats() sleep(1) except KeyboardInterrupt: textutils.output_info( 'Keyboard Interrupt Received, cleaning up threads') # Clean reference to sockets database.connection_pool = None database.kill_received = True # Kill remaining workers but don't join the queue (we want to abort:)) for worker in workers: if worker is not None and worker.isAlive(): worker.kill_received = True worker.join(0) # Set leftover done in cas of a kill. while not queue.empty(): queue.get() queue.task_done() break # Make sure everything is done before sending control back to application textutils.output_debug("Threads: joining queue of size: " + str(queue.qsize())) queue.join() textutils.output_debug("Threads: join done") # Make sure we get all the worker's results before continuing the next step for worker in workers: if worker is not None and worker.isAlive(): worker.kill_received = True worker.join()
def wait_for_idle(self, workers, queue): """ Wait until fetch queue is empty and handle user interrupt """ while not database.kill_received and not queue.empty(): try: # Make sure everything is done before sending control back to application textutils.output_debug("Threads: joining queue of size: " + str(queue.qsize())) queue.join() textutils.output_debug("Threads: join done") except KeyboardInterrupt: try: stats.output_stats(workers) sleep(1) # The time you have to re-press ctrl+c to kill the app. except KeyboardInterrupt: textutils.output_info('Keyboard Interrupt Received, waiting for blocking threads to exit') # Clean reference to sockets database.connection_pool = None database.kill_received = True self.kill_workers(workers) sys.exit(0) # Make sure we get all the worker's results before continuing the next step self.kill_workers(workers)
def wait_for_idle(self, workers, queue): """ Wait until fetch queue is empty and handle user interrupt """ while not database.kill_received and not queue.empty(): try: sleep(0.1) except KeyboardInterrupt: try: stats.output_stats() sleep(1) except KeyboardInterrupt: textutils.output_info('Keyboard Interrupt Received, cleaning up threads') # Clean reference to sockets database.connection_pool = None database.kill_received = True # Kill remaining workers but don't join the queue (we want to abort:)) for worker in workers: if worker is not None and worker.isAlive(): worker.kill_received = True worker.join(0) # Set leftover done in cas of a kill. while not queue.empty(): queue.get() queue.task_done() break # Make sure everything is done before sending control back to application textutils.output_debug("Threads: joining queue of size: " + str(queue.qsize())) queue.join() textutils.output_debug("Threads: join done") # Make sure we get all the worker's results before continuing the next step for worker in workers: if worker is not None and worker.isAlive(): worker.kill_received = True worker.join()