Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Kill PythonShell.run() script when condition is met, and start another script

My question is essentially the title. I currently have a file/module for running python scripts. Lets call it script.js which looks like this:

const PythonShell = require('python-shell').PythonShell;

class AHK {
   static async runScript() {
    PythonShell.run('/ahk/runScript.py', null, function (err) {
      if (err) throw err;
      console.log('finished');
    });
  }

  static async runOtherScript() {
    PythonShell.run('/ahk/runOtherScript.py', null, function (err) {
      if (err) throw err;
      console.log('finished');
    });
  }
}

module.exports = AHK;

I have my main.js file which imports this module and executes the function and looks like this:

const AHK = require("./ahk");

AHK.runScript();

Right now I have the python script ending after a certain amount of time. I'd like to have it so I can run the python script until something changes on the js side, kill that script, and then start the other one. Pseudo code for this would be something like:

const AHK = require("./ahk");

AHK.runScript();

if(requirement = true){
// kill AHK.runScript() here
// start AHK.runOtherScript();
}

or something along this line

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!