gpt4 book ai didi

python - 如何为nodejs运行像pm2这样的python脚本

转载 作者:IT老高 更新时间:2023-10-28 20:49:21 37 4
gpt4 key购买 nike

我已将 pm2 用于我的 Node.js 脚本,我喜欢它。
现在我有一个 python 脚本,可以收集 EC2 上的流数据。有时脚本会爆炸,我希望进程管理器像 pm2 一样重新启动自己。

有没有和python的pm2一样的东西?我一直在四处寻找,找不到任何东西。

这是我的错误

  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 430, in filter
self._start(async)
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 346, in _start
self._run()
File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 286, in _run
raise exception
AttributeError: 'NoneType' object has no attribute 'strip'
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90:

这是一个简单的数据收集脚本

class StdOutListener(StreamListener):

def on_data(self, data):
mydata = json.loads(data)
db.raw_tweets.insert_one(mydata)
return True

def on_error(self, status):
mydata = json.loads(status)
db.error_tweets.insert_one(mydata)


if __name__ == '__main__':

#This handles Twitter authetification and the connection to Twitter Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)

#This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
stream.filter(follow=[''])

我希望它在发生某些事情时重新启动。

最佳答案

您实际上可以在 pm2 中运行 python 脚本:

pm2 start echo.py

如果脚本以 .py 后缀结尾,它将默认使用 python 解释器。如果您的文件名不以 .py 结尾,您可以这样做:

pm2 start echo --interpreter=python

我发现你必须小心你使用的是哪个 python,特别是如果你使用的 virtualenv python 与你机器上的“默认”python 版本不同。

关于python - 如何为nodejs运行像pm2这样的python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32127834/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com