When a button is clicked in my HTML,let us say "connect" button, it will execute a python script. What I wanted to do is when another button, say "disconnect", is clicked, the python script which was previously launched will be terminated. I searched for answers already but I can't get it right. I thought of launching another python script that will eventually terminate the already running script. would that be possible?
from JS
function connect(){
$.ajax({
url: "python-scripts/connect.py",
success: function(response) {
}
});
}
function disconnect(){
$.ajax({
url: "python-scripts/disconnect.py",
success: function(response) {
}
});
}
connect.py
while True:
print "test"
i want disconnect.py to terminate connect.py
I saw these answered questions but I do not know how to properly use it in python since I am still new to it.
Terminate a python script from another python script
How to stop another already running script in python?
or atleast, can somebody tell me how this works?
from subprocess import check_call
import sys
script = sys.argv[1]
check_call(["pkill", "-9", "-f", script])