Created
June 3, 2013 15:28
-
-
Save oogali/5698996 to your computer and use it in GitHub Desktop.
Example of using sched in Python
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 os | |
| import sys | |
| import time | |
| import sched | |
| def jumpoff(arg=None): | |
| print "[%f] It's the jumpoff! (%s)" % (time.time(), str(arg)) | |
| return | |
| def sleep(units): | |
| if units == 0: | |
| print "Yielding..." | |
| return | |
| print "[%f] We are going to sleep for %f units" % (time.time(), units) | |
| time.sleep(units) | |
| def main(argv=None): | |
| if argv is None: | |
| argv = sys.argv | |
| s = sched.scheduler(time.time, sleep) | |
| s.enter(10, None, jumpoff, argument=(1,)) | |
| print "Queue\n=====" | |
| print s.queue | |
| s.run() | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment