Problem to exit main code from thread

This is the place for queries that don't fit in any of the other categories.

Problem to exit main code from thread

Postby goueg83460 » Thu Nov 28, 2013 9:50 am

Hello, I am new with python. I am trying to made a thread that exit main in case a timeout has been reached.

Here is my code. I see during execution that end of thread has happened but I do not know how to force the code to stop.

-----------------
Code: Select all
import threading
import time
import sys

def main():
  t1_stop= threading.Event()
  t1 = threading.Thread(target=thread1, args=(5, t1_stop))
  t1.start()
  print 'thread 1 set'
  while True:
    print "blablabla"
    time.sleep(1)

def thread1(time, stop_event):
  while(not stop_event.is_set()):
      #equivalent to time.sleep()
      print 'thread 1'
      stop_event.wait(time)
     
main()


Thanks in advance for your help.
Last edited by stranac on Thu Nov 28, 2013 10:30 am, edited 2 times in total.
Reason: First post lock. Changed the title misspelling.
goueg83460
 
Posts: 1
Joined: Thu Nov 28, 2013 9:47 am

Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 7 guests