magnate.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:stellarmagnate 作者: abadger 项目源码 文件源码
def run(self):
        """
        Run the program.  This is the main entrypoint to the magnate client
        """
        # Create the statedir if it doesn't exist
        if not os.path.exists(self.cfg['state_dir']):
            os.makedirs(self.cfg['state_dir'])

        twiggy_addon.dict_config(self.cfg['logging'])

        ui_plugins = load('magnate.ui', subclasses=UserInterface)
        for UIClass in ui_plugins:  #pylint: disable=invalid-name
            if UIClass.__module__.startswith('magnate.ui.{}'.format(self.cfg['ui_plugin'])):
                break
        else:
            print('Unknown user ui: {}'.format(self.cfg['ui_plugin']))
            return 1

        # Try using uvloop instead of the asyncio event loop
        if self.cfg['use_uvloop']:
            try:
                import uvloop
            except:
                print('Could not import uvloop.  Falling back on asyncio event loop')
            try:
                asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
            except:
                print('Could not set uvloop to be the event loop.  Falling back on asyncio event loop')

        loop = asyncio.get_event_loop()
        self.pubpen = PubPen(loop)
        self._setup_markets()
        self.dispatcher = Dispatcher(self, self.markets)

        # UIClass is always available because we'd have already returned (via
        # the for-else) if UIClass was not defined
        try:
            user_interface = UIClass(self.pubpen, self.cfg['ui_args']) #pylint: disable=undefined-loop-variable
            return user_interface.run()
        except Exception as e:
            log.trace('error').error('Exception raised while running the user interface')
            raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号