本文整理汇总了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!')