Skip to content

Instantly share code, notes, and snippets.

@ViktorovEugene
Last active April 29, 2016 14:12
Show Gist options
  • Save ViktorovEugene/8853e3d6f0d7adedeb54c5d41b4f70d8 to your computer and use it in GitHub Desktop.
Save ViktorovEugene/8853e3d6f0d7adedeb54c5d41b4f70d8 to your computer and use it in GitHub Desktop.
Councurent execution with dalay
"""
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