client-shutdown-callback.py 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # PYTHON_ARGCOMPLETE_OK
  3. import sys
  4. import jack
  5. import time
  6. import argparse
  7. from gi.repository import GLib
  8. def shutdown(client, reason, loop):
  9. print(reason)
  10. loop.quit()
  11. def run():
  12. loop = GLib.MainLoop()
  13. client = jack.Client('client shutdown callback example');
  14. client.set_shutdown_callback(shutdown, loop)
  15. client.activate();
  16. print('client name: ' + client.get_name())
  17. try:
  18. loop.run()
  19. except KeyboardInterrupt:
  20. print('keyboard interrupt')
  21. def _init_argparser():
  22. argparser = argparse.ArgumentParser(description = None)
  23. return argparser
  24. def main(argv):
  25. argparser = _init_argparser()
  26. try:
  27. import argcomplete
  28. argcomplete.autocomplete(argparser)
  29. except ImportError:
  30. pass
  31. args = argparser.parse_args(argv)
  32. run(**vars(args))
  33. return 0
  34. if __name__ == '__main__':
  35. sys.exit(main(sys.argv[1:]))