0

This is the second day I've been puzzling over it. The situation is as follows. I start the bot with the command subprocess.Popen('stater.bat',cwd='F:/1/bot/', shell=True). Everything works, but I need the ability to shut down the bot. And that's the whole problem. I don't know how to turn the bot off. Another factor is that there will be 3+ of these bots running at once. And flexibility is needed, ie exactly what I need bot to turn off and on (this I can do). Help solve the problem with the closure of the child process.

Popen.kill(), but this not work. It's kill main bot, but children bot work

The idea is to get the PIDs of the child processes and kill them with a command, but how to get the PIDs of the child processes?

Xcen
  • 1
  • 2
  • Python isn't really a shell scripting language; things like this are curiously hard in it. – 2e0byo Nov 30 '22 at 19:00
  • 1
    Unless you started the children bots, it's not your job to kill them. The main bot should be responsible for killing the children it spawned when before it exits, regardless of why it is exiting. (That's why `kill -9` is a last resort: it doesn't give the targeted process a chance to do it pre-exit cleanup.) – chepner Nov 30 '22 at 19:00
  • 1
    @2e0byo This is no harder in Python than it is in shell, which is to say simply killing a process doesn't necessarily kill its children no matter which language you are using to issue the signal. – chepner Nov 30 '22 at 19:01
  • @chepner I just meant I found the process api a bit clunky in python. Though it's more an ecosystem thing now I think of it. And indeed. Windows in particular seems to delight in *not* killing children when the parent dies. – 2e0byo Nov 30 '22 at 21:48

0 Answers0