Handle KeyboardInterrupt properly in cqlsh

Patch by Jordon Pittier, reviewed by brandonwilliams for CASSANDRA-5481
This commit is contained in:
Brandon Williams 2014-07-29 13:57:42 -05:00
parent 192596ad75
commit 249bbfc3b2
1 changed files with 12 additions and 8 deletions

View File

@ -504,15 +504,9 @@ class Shell(cmd.Cmd):
self.conn = use_conn
else:
transport = transport_factory(hostname, port, os.environ, CONFIG_FILE)
self.conn = cql.connect(hostname, port, user=username, password=password,
cql_version=cqlver, transport=transport)
self.conn = cql.connect(hostname, port, keyspace=keyspace, user=username,
password=password, cql_version=cqlver, transport=transport)
self.set_expanded_cql_version(cqlver)
# we could set the keyspace through cql.connect(), but as of 1.0.10,
# it doesn't quote the keyspace for USE :(
if keyspace is not None:
tempcurs = self.conn.cursor()
tempcurs.execute('USE %s;' % self.cql_protect_name(keyspace))
tempcurs.close()
self.cursor = self.conn.cursor()
self.get_connection_versions()
@ -1056,6 +1050,16 @@ class Shell(cmd.Cmd):
except CQL_ERRORS, err:
self.printerr(str(err))
return False
except KeyboardInterrupt:
self.cursor.close()
self.conn.terminate_connection()
transport = self.transport_factory(self.hostname, self.port,
os.environ, CONFIG_FILE)
self.conn = cql.connect(self.hostname, self.port, keyspace=self.keyspace,
user=self.username, password=self.password,
cql_version=self.cql_version, transport=transport)
self.cursor = self.conn.cursor()
return False
except Exception, err:
import traceback
self.printerr(traceback.format_exc())