Skip to content

Instantly share code, notes, and snippets.

@noonat
Created February 23, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noonat/7561a7ff0d675c48a8f7763ad60cc62b to your computer and use it in GitHub Desktop.
Save noonat/7561a7ff0d675c48a8f7763ad60cc62b to your computer and use it in GitHub Desktop.
Spawn a thread and make the greenlet wait for it to exit.
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