Skip to content

Instantly share code, notes, and snippets.

@beatak
Created January 3, 2014 01:39
Show Gist options
  • Select an option

  • Save beatak/8231021 to your computer and use it in GitHub Desktop.

Select an option

Save beatak/8231021 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import threading
global_var = { 'handler': None, 'sec_wait': 1.0 }
def cb_success ():
print( 'success!' )
def cb_cancel ():
if global_var['sec_wait'] >= 5.0:
print('canceling')
cb_success()
global_var['handler'].cancel()
else:
print( 'wait: %d' % global_var['sec_wait'] )
func_master()
def func_master():
w = global_var['sec_wait'] = global_var['sec_wait'] + 1.0
print( 'master: wait: %d' % w )
global_var['handler'] = threading.Timer( w, cb_cancel )
global_var['handler'].start()
func_master()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment