Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda