(Crossposting from Stackoverflow, where I unfortunately didn't get any 
answers: 
https://stackoverflow.com/questions/58837864/sqlalchemty-how-to-kill-a-mysql-process-on-keyboard-interrupt
 
)

Hello!

I'm using SQLAlchemy 1.3.10 to run a bunch of SQL statements on Percona 
Server 5.7.27. I do not use the ORM functionality. My problem is that I 
cannot abort the running SQL statement from KeyboardInterrupt handler, 
after hitting Ctrl-C.

My usage is as follows:

engine = create_engine(...)
connection = engine.connect()with connection.begin() as transaction:
  try:
    res = connection.execute(text(sql))
  except KeyboardInterrupt as ctrlc:
    print('You pressed ctrl-c')
    transaction.rollback()
    sys.exit(1)


Pressing Ctrl-c stops the script but leaves the query running in MySQL 
server, and i have to kill it manually using KILL pid. 

I've tried to call connection.close() as well, but without result. How can 
I kill such running query on keyboard interrupt?


Best regards,


Marcin Koziej

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/426f7140-d078-41fa-81d7-a5a6aabb2a7f%40googlegroups.com.

Reply via email to