gpt4 book ai didi

python - supervisord 事件监听器

转载 作者:太空狗 更新时间:2023-10-30 01:09:15 35 4
gpt4 key购买 nike

我正在尝试为 supervisord 配置一个事件监听器,但无法让它工作。我只想监听 PROCESS_STATE 变化并运行一些触发 urllib2request 的 python 代码。

在我的 .conf 中我有:

[eventlistener:statechanges]
command=python listener.py
events=PROCESS_STATE

在 listener.py 中:

def run():    
runFunc() # Function to trigger an urllib2request

if __name__ == '__main__':
run()

然后触发器不会启动,它只是在重试一些之后进入FATAL状态。

statechanges entered FATAL state, too many start retries too quickly

任何想法或有人有如何为 supervisord 编写监听器的示例吗?

最佳答案

你不能只打印随机字符串,supervisord 在 stdout 监听 :)

文档中的这个例子怎么样:

import sys

def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()

def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()

def main():
while 1:
write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
line = sys.stdin.readline() # read header line from stdin
write_stderr(line) # print it out to stderr
headers = dict([ x.split(':') for x in line.split() ])
data = sys.stdin.read(int(headers['len'])) # read the event payload
write_stderr(data) # print the event payload to stderr
write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED

if __name__ == '__main__':
main()
import sys

http://supervisord.org/events.html#example-event-listener-implementation

关于python - supervisord 事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15085623/

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