我确保towork()
函数创建一个线程,并且在 h5 中,我可以收到“准备工作” 。但是在subprocess.Popen()
之后,我无法收到'成功'或'失败',它似乎停止了。
有帮助吗?
this is part of flask
@socketio.on('work')
def towork():
t=threading.Thread(target=test)
t.start()
def test():
socketio.emit('listen',{'res':'ready to work'})
cmd='dir'
out=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
status=out.wait()
if status==0:
socketio.emit('listen',{'res':'sucess'})
else:
socketio.emit('listen',{'res':'failed'})
part of h5
socket.on("listen",function(msg){
$('#show').append(`<p>{msg.res}</p>`);
});