ctrl+c dosen’t cancel a running Python script that uses threads?! /gasp

welp, ctrl+c is my best friend when it comes to bailing out of a program where I screwed up or is taking too long for my gamer-esque patience

It turns out you actually gotta kill -9 the process!

The answer to “why” this is the case is around 22:00 to 25:00 in this  presentation, “Inside the Python GIL”  by David Beazley:

This came about as recently I’ve been working on a Rackspace Cloud Files container replication program, and I’ve been working on trying to speed it up in ways so that it completes in a “reasonable” amount of time.   

I first gave it a shot at it with the multiprocessing module.  Soon enough though I found I couldn’t use it due to the inability to pickle an SSLObject.  Which, I guess the cloudfiles.connection.Connection I was using to connect to the Cloud Files container was using.

At this point I went searching for an answer, and tangentially discovered that Cloud Files’ origin was actually from a separate company named Mosso, which Rackspace acquired and turned into their cloud service thingy!

My second try was more successful:  using the threading and Queue modules to create a specified number of worker threads to run replicate() method over a queue of container objects.

And this is where I discovered this ctrl+c weirdness/intricacy.  I’d have a bug or some stack happening which I could see from the debug output.  Wanting to exit out early, I’d bang on ctrl+c to absolutely no avail!  Sooooo weird!  haha

 

Leave a Reply

Your email address will not be published. Required fields are marked *