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))
  print 'thread 1 set'
  while True:
    print "blablabla"

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

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.
Posts: 1
Joined: Thu Nov 28, 2013 9:47 am

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests