您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 channel_name == 'wxy':
  27. os.environ['WECHATY_LOG']="warn"
  28. # os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = '127.0.0.1:9001'
  29. channel = channel_factory.create_channel(channel_name)
  30. if channel_name in ['wx','wxy','wechatmp']:
  31. PluginManager().load_plugins()
  32. # startup channel
  33. channel.startup()
  34. except Exception as e:
  35. logger.error("App startup failed!")
  36. logger.exception(e)
  37. if __name__ == '__main__':
  38. run()