Created
February 23, 2017 19:16
-
-
Save noonat/7561a7ff0d675c48a8f7763ad60cc62b to your computer and use it in GitHub Desktop.
Spawn a thread and make the greenlet wait for it to exit.
This file contains 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
from __future__ import print_function | |
import time | |
import gevent | |
from gevent import hub, _threading | |
def ticker(): | |
while True: | |
print('tick') | |
gevent.sleep(1) | |
def listen(): | |
def worker(): | |
time.sleep(5) | |
watcher.send() | |
watcher = hub.get_hub().loop.async() | |
_threading.start_new_thread(worker, ()) | |
hub.get_hub().wait(watcher) | |
gevent.spawn(ticker) | |
print('listen starting') | |
listen() | |
print('listen stopped') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment