From d07bddc15331e56d3906144a4938e2f4f951bfdb Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Mon, 20 Sep 2010 17:44:07 -0400 Subject: [PATCH 1/2] Disable KeyboardInterrupt, just exit on SIGINT. The KeyboardInterrupt exception doesn't get raised if the script is stuck in a blocking call, i.e., inside the check_event function. So pressing CTRL+C has no effect. This patch disables the exception, reverting to the OS' default behaviour for the SIGINT signal (i.e., terminate the program). --- pgloader.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pgloader.py b/pgloader.py index 494e57d..2178ced 100755 --- a/pgloader.py +++ b/pgloader.py @@ -663,7 +663,6 @@ def load_data(): started = {} finished = {} current = 0 - interrupted = False max_running = MAX_PARALLEL_SECTIONS if max_running == -1: @@ -734,11 +733,6 @@ def load_data(): log.error("can't open '%s' with given input encoding '%s'" \ % (filename, input_encoding)) - except KeyboardInterrupt: - interrupted = True - log.warning("Aborting on user demand (Interrupt)") - break - except IOError, e: # typically, No Space Left On Device, can't report nor continue break @@ -756,7 +750,7 @@ def load_data(): td = time.time() - begin retcode = 0 - if SUMMARY and not interrupted: + if SUMMARY: try: retcode = print_summary(None, sections, summary, td) print @@ -769,6 +763,9 @@ def load_data(): return retcode if __name__ == "__main__": + # Disable KeyboardInterrupt, just exit on CTRL+C + import signal, os + signal.signal(signal.SIGINT, signal.SIG_DFL) try: ret = load_data() except Exception, e: @@ -782,9 +779,5 @@ if __name__ == "__main__": sys.stderr.write(str(e) + '\n') sys.exit(1) - except KeyboardInterrupt, e: - sys.stderr.write(str(e) + '\n') - sys.exit(1) - sys.exit(ret) From a206b18f8b9362b1adf6a2f4f3fce01b51ab072c Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Mon, 27 Sep 2010 11:32:12 -0400 Subject: [PATCH 2/2] better import placement --- pgloader.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pgloader.py b/pgloader.py index 2178ced..53c8c3e 100755 --- a/pgloader.py +++ b/pgloader.py @@ -5,7 +5,7 @@ PostgreSQL data import tool, see included man page. """ -import os, sys, os.path, time, codecs, logging, threading +import os, sys, os.path, time, codecs, logging, threading, signal from cStringIO import StringIO import pgloader.options @@ -764,7 +764,6 @@ def load_data(): if __name__ == "__main__": # Disable KeyboardInterrupt, just exit on CTRL+C - import signal, os signal.signal(signal.SIGINT, signal.SIG_DFL) try: ret = load_data()