【发布时间】:2016-06-12 13:55:45
【问题描述】:
我正在尝试制作一个 Python 程序,该程序将在 AWS(通过 Elastic Beanstalk 部署)上运行,该程序侦听 STOMP 队列(基于 TCP 的简单文本协议)。我正在使用stomp.py 库,docs here。
这是程序,我正在使用 PyCharm 的“运行应用程序”功能运行它:
# PyPI imports
import stomp
# TODO: TESTING ONLY, REMOVE WHEN DONE!
import time
def main():
'''Starts the STOMP listener.'''
print('Running main function')
# See the following example for the template this file was based on:
# http://jasonrbriggs.github.io/stomp.py/quickstart.html
conn = stomp.Connection([('example.com', 61613)],
auto_decode=False)
conn.set_listener('print', stomp.PrintingListener())
conn.start()
conn.connect(username = 'username', passcode = 'password', wait=False)
conn.subscribe(destination='/destination',
id=1,
ack='auto')
time.sleep(30)
if __name__ == '__main__':
main()
它工作得很好,打印出队列消息,但只有 30 秒,然后它停止运行并输出:
Process finished with exit code 0
如果你注释掉 sleep 函数,它会运行 main 函数,然后立即结束进程。
但如果你在 Python 解释器中写出来,它会继续无限期地打印出队列消息。
如何通过 PyCharm 的“运行应用程序”选项让程序无限期地运行?或者当我弄清楚如何部署程序时,AWS Elastic Beanstalk 会处理这个问题吗?
我对 Python 很生疏,而且对部署实际的 Python 应用程序很陌生,所以如果这是一个明显的问题/答案,我深表歉意。
【问题讨论】:
标签: python pycharm amazon-elastic-beanstalk stomp