Created
January 3, 2014 01:39
-
-
Save beatak/8231021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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