当前位置: 首页>>代码示例>>Python>>正文


Python Shove.start方法代码示例

本文整理汇总了Python中shove.Shove.start方法的典型用法代码示例。如果您正苦于以下问题:Python Shove.start方法的具体用法?Python Shove.start怎么用?Python Shove.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shove.Shove的用法示例。


在下文中一共展示了Shove.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from shove import Shove [as 别名]
# 或者: from shove.Shove import start [as 别名]
def main():
    """Connect to RabbitMQ and listen for orders from the captain indefinitely."""
    # Display logging to commandline for more readable output.
    logging.basicConfig(format='%(asctime)s - %(levelname)s: %(message)s', level=logging.INFO)

    # Attempt to load settings from environment, and if that fails, fallback to a local settings
    # file.
    try:
        settings = imp.load_source('shove.settings', os.environ['SHOVE_SETTINGS_FILE'])
    except (ImportError, KeyError):
        log.warning('Failed to import settings from environment variable, falling back to local '
                    'file.')
        try:
            directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
            settings = imp.load_source('shove.settings', os.path.join(directory, 'settings.py'))
        except ImportError:
            log.warning('Error importing settings.py, did you copy settings.py-dist yet?')
            sys.exit(1)

    adapter = RabbitMQAdapter(
        host=settings.RABBITMQ_HOST,
        port=settings.RABBITMQ_PORT,
        queue=settings.QUEUE_NAME,
        virtual_host=settings.RABBITMQ_VHOST,
        username=settings.RABBITMQ_USER,
        password=settings.RABBITMQ_PASS
    )
    shove = Shove(settings.PROJECTS, adapter)

    # If a SIGINT is sent to the program, shut down the connection and exit.
    def sigint_handler(signum, frame):
        log.info('Received SIGINT, shutting down connection.')
        shove.stop()
    signal.signal(signal.SIGINT, sigint_handler)

    log.info('Awaiting orders, sir!')
    try:
        shove.start()
    except KeyboardInterrupt:
        shove.stop()
        log.info('Standing down and returning to base, sir!')
开发者ID:solarce,项目名称:shove,代码行数:43,代码来源:cmd.py


注:本文中的shove.Shove.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。