Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

49 lignes
1.3KB

  1. # encoding:utf-8
  2. import os
  3. from config import conf, load_config
  4. from channel import channel_factory
  5. from common.log import logger
  6. from plugins import *
  7. import signal
  8. import sys
  9. def sigterm_handler_wrap(_signo):
  10. old_handler = signal.getsignal(_signo)
  11. def func(_signo, _stack_frame):
  12. logger.info("signal {} received, exiting...".format(_signo))
  13. conf().save_user_datas()
  14. return old_handler(_signo, _stack_frame)
  15. signal.signal(_signo, func)
  16. def run():
  17. try:
  18. # load config
  19. load_config()
  20. # ctrl + c
  21. sigterm_handler_wrap(signal.SIGINT)
  22. # kill signal
  23. sigterm_handler_wrap(signal.SIGTERM)
  24. # create channel
  25. channel_name=conf().get('channel_type', 'wx')
  26. if "--cmd" in sys.argv:
  27. channel_name = 'terminal'
  28. if channel_name == 'wxy':
  29. os.environ['WECHATY_LOG']="warn"
  30. # os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = '127.0.0.1:9001'
  31. channel = channel_factory.create_channel(channel_name)
  32. if channel_name in ['wx','wxy','terminal','wechatmp','wechatmp_service']:
  33. PluginManager().load_plugins()
  34. # startup channel
  35. channel.startup()
  36. except Exception as e:
  37. logger.error("App startup failed!")
  38. logger.exception(e)
  39. if __name__ == '__main__':
  40. run()