def run(self, stop_after=0):
     st = StoppableThread()
     st.start()
     
     time.sleep(stop_after)
     st.stop()
     st.join()
 def test_06_sleep_interrupt(self):
     st = StoppableThread()
     
     # basic interruptable sleep
     start = time.time()
     st._interruptable_sleep(2)
     took = time.time() - start
     assert took < 2.6 # take into account interval on interruptable sleep
     
     # advanced interruptable sleep
     start = time.time()
     st._interruptable_sleep(3, 0.1)
     took = time.time() - start
     assert took < 4.3, took
     
     # now try interrupting the sleep (need to use a special wrapper
     # class defined above to get this done)
     start = time.time()
     InterruptTester().run(2)
     took = time.time() - start
     assert took < 3 # taking into account all the sleep delays
 def test_05_run_stop(self):
     st = StoppableThread()
     assert not st.stopped()
     
     st.stop()
     assert st.stopped()