这个问题在这里已有答案:
这是Python脚本:
import json
import subprocess
from websocket import create_connection
ws = create_connection("wss://ws.blockchain.info/inv")
ws.send("""{"op":"unconfirmed_sub"}""")
while True:
tx = ws.recv()
data_decoded=json.loads(tx)
for i in range(0, len(data_decoded['x']['in'])):
address=data_decoded['x']['in'][i]['addr']
if address != None:
if address.startswith('1'):
subprocess.run(['php', '', address])
该脚本连接到websocket并将信息中继到服务器 .
我想弄清楚如何做两件事:
-
如果websocket断开连接,如何停止脚本?
-
如果脚本停止,我该如何自动重启它以确保它全天候运行?包括如果答案#1杀死它,服务器重新启动等 .
我在Python 3中运行它,我的操作系统是Ubuntu 18.04 .