SHARE
TWEET

Untitled

a guest Aug 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2. import functools
  3. import os
  4. import signal
  5.  
  6. def ask_exit(signame):
  7.     print("got signal %s: exit" % signame)
  8.     loop.stop()
  9.  
  10. loop = asyncio.get_event_loop()
  11. for signame in ('SIGINT', 'SIGTERM'):
  12.     loop.add_signal_handler(getattr(signal, signame),
  13.                             functools.partial(ask_exit, signame))
  14.  
  15. print("Event loop running forever, press Ctrl+C to interrupt.")
  16. print("pid %s: send SIGINT or SIGTERM to exit." % os.getpid())
  17. try:
  18.     loop.run_forever()
  19. finally:
  20.     loop.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top