简体   繁体   English

终止python烧瓶中的子进程

[英]Terminating a subprocess in python flask

I have a flask application in which I have to run a bash script.我有一个烧瓶应用程序,我必须在其中运行一个 bash 脚本。 On visiting a particular link (let say localhost:5000/B) I execute the script using python's subprocess library.在访问特定链接时(比如说 localhost:5000/B),我使用 python 的子进程库执行脚本。 Then used wait() function on subprocess.然后在子进程上使用 wait() 函数。 So that the script is finished before doing other tasks which depend on script.以便在执行其他依赖于脚本的任务之前完成脚本。 After finishing those remaining tasks I return the results in response by rendering a template.在完成剩余的任务后,我通过渲染模板返回结果作为响应。

Sometimes I might go back from page or press cancel button( on top side of browser).有时我可能会从页面返回或按取消按钮(在浏览器的顶部)。 In that case I want to terminate that script from running even if it has not completed.在这种情况下,即使该脚本尚未完成,我也想终止该脚本的运行。 I have added javascript in page so that when I go back from page it makes a GET request to server at link localhost:5000/C.我在页面中添加了 javascript,这样当我从页面返回时,它会向链接 localhost:5000/C 的服务器发出 GET 请求。 In the function handling this, I terminate the subprocess.在处理这个的函数中,我终止了子进程。

But due to some reasons it does not work, even after using kill() or terminate() method.但由于某些原因,即使使用了 kill() 或 terminate() 方法,它也不起作用。

Can we terminate a subprocess on which we have used wait() or not?我们可以终止使用了 wait() 的子进程吗? If there is a better way of doing this thing kindly let me know.如果有更好的方法来做这件事,请告诉我。

Thanks谢谢

该子流程在执行期间正在创建另一个子流程,并且正在产生问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM