Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Terminating a function
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Ian Leitch, post: 1864887"] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 You can use a thread to do the timing and send an interrupt when the time is up: #!/usr/bin/python import thread import threading from time import sleep def timer_thread(): sleep(10) thread.interrupt_main() def my_func(): try: while 1: sleep(2) print "Hello" except KeyboardInterrupt: return my_thread = threading.Thread(target=timer_thread) my_thread.start() my_func() print "Done." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFD9hxcefZ4eWAXRGIRAnwIAKCH/pH7dyzjk1rsfvFKzrA48GgeEACfdNx6 QmsqAruOESUe2bzPTh/nsE8= =LvT6 -----END PGP SIGNATURE----- [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Terminating a function
Top