0

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])
6
  • 1
    please post the code you've tried. Commented Nov 25, 2017 at 15:21
  • @sam-pyt oh I'm sorry. I edited it already Commented Nov 25, 2017 at 15:42
  • ok this type of thing depends on OS, so are you Windows? Unix or MacOS? Commented Nov 25, 2017 at 15:46
  • @sam-pyt Windows Commented Nov 25, 2017 at 15:47
  • I just saw your links up there. you won't get much better answers for this question than those. Commented Nov 25, 2017 at 15:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.