-
Notifications
You must be signed in to change notification settings - Fork 221
Closed
Labels
Description
Describe the bug
.kill() do not kill python process spawned when { shell: true }
is defined. I checked this awesome thread on stackoverflow, but I don't think this can be done here, since I'm not finding the PID of the spawned process. (PythonShell
do not have a pid property)
Python code
import time
import sys
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def writelines(self, datas):
self.stream.writelines(datas)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout = Unbuffered(sys.stdout)
x = 1
while True:
print(f'{x}: test if this could be killed with shell: true')
time.sleep(10)
x += 10
Javascript code
const options = { scriptPath: 'C:\\users\\leona\\iq\\iq-websocket\\python\\botR', shell: true};
const pyTeste = new PythonShell('teste.py', options);
pyTeste
.on('message', (line: string) => {
console.log(line);
})
.on('stderr', (std: string) => {
console.log(std);
})
.on('error', err => {
console.log('err');
console.log(err);
})
.on('close', () => {
console.log('Programa finalizado');
});
// this function do not work
setTimeout(() => {
pyTeste.kill();
}, 10000);
Expected behavior
The library to check this situation and kill both the shell
where the script is running and the script itself.
Actual behavior
The python program is never killed.
Other Information (please complete the following information):
- OS: Windows10
- Python Version 3.8.7
- Node Version 12.15.0