Python threads in Komodo

I’m trying to spawn threads in Python/Komodo. It works standalone but in Komodo it does not appear that the treads get active. (I also can’t figure out how to get indents to work properly on this forum post so ignore the obvious indent problems). I don’t see any print output when I run this in Komodo but outside of Komodo I do. I’ve tried another version where I’m writing to a database and nothing is being written and no exceptions are thrown (when in Komodo). What am I missing?

Thanks,
Charlie

import thread
import time

def print_time( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
      print "%s: %s" % ( threadName, time.ctime(time.time()) )


try:
   thread.start_new_thread( print_time, ("Thread-1", 2, ) )
   thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass

I would suggest reading the threading documentation. It’s never a good idea to copy code from the “problem part” of a stackoverflow question, because it obviously has a problem. If you’re interested in running that particular bit of code just check the solution in that stackoverflow question.

Be sure to read up about the Python GIL before you really delve into threads though, as it significantly limits what you can and cannot do with Python threads.

Hi Nathan,

Thanks for the reply.

The code I included is not my real code. I included that just for illustration.

My threads are now working. The problem I am having is specific to Komodo: If I include print statements or breakpoints in the worker thread (as opposed to the main thread), I do not see output (print) and the breakpoint is not tripped. So what I am trying to figure out is how to get Komodo IDE to give me visibility and control over a thread that is not the main thread.

Thanks,
Charlie