Last active
April 29, 2016 14:12
-
-
Save ViktorovEugene/8853e3d6f0d7adedeb54c5d41b4f70d8 to your computer and use it in GitHub Desktop.
Councurent execution with dalay
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
""" | |
Will not fail until the `value` in gevent.sleep(<value>) will be more than | |
timeout value. | |
""" | |
from __future__ import print_function | |
import time | |
import gevent | |
from gevent import Timeout | |
seconds = 1 | |
timeout = Timeout(seconds) | |
timeout.start() | |
def wait_1(): | |
for i in range(3): | |
time.sleep(1) | |
print('.') | |
gevent.sleep(0) | |
print('\nExit 1') | |
def wait_2(): | |
for i in range(3): | |
time.sleep(1) | |
print(',') | |
gevent.sleep(0) | |
print('\nExit 2') | |
try: | |
gevent.joinall([gevent.spawn(wait_1), gevent.spawn(wait_2)]) | |
except Timeout: | |
print('Could not complete') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment