Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

python-shell

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-shell - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

test/python/infinite_loop.py

0

CHANGELOG.md

@@ -0,0 +0,0 @@ ## 0.0.3

25

index.js

@@ -86,4 +86,5 @@ var EventEmitter = require('events').EventEmitter;

this.childProcess.on('exit', function (code) {
this.childProcess.on('exit', function (code,signal) {
self.exitCode = code;
self.exitSignal = signal;
terminateIfNeeded();

@@ -93,7 +94,6 @@ });

function terminateIfNeeded() {
if (!self.stderrHasEnded || !self.stdoutHasEnded || self.exitCode == null) {
return;
}
if(!self.stderrHasEnded || !self.stdoutHasEnded || (self.exitCode == null && self.exitSignal == null)) return;
var err;
if (errorData || self.exitCode !== 0) {
if (errorData || (self.exitCode && self.exitCode !== 0)) {
if (errorData) {

@@ -116,6 +116,7 @@ err = self.parseError(errorData);

}
self.terminated = true;
self.emit('close');
self._endCallback && self._endCallback(err);
}
self._endCallback && self._endCallback(err,self.exitCode,self.exitSignal);
};
};

@@ -251,2 +252,12 @@ util.inherits(PythonShell, EventEmitter);

/**
* Closes the stdin stream, which should cause the process to finish its work and close
* @returns {PythonShell} The same instance for chaining calls
*/
PythonShell.prototype.terminate = function (signal) {
this.childProcess.kill(signal);
this.terminated = true;
return this;
};
module.exports = PythonShell;
{
"name": "python-shell",
"version": "0.4.0",
"version": "0.5.0",
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio",

@@ -5,0 +5,0 @@ "keywords": [

@@ -74,5 +74,8 @@ # python-shell

// end the input stream and allow the process to exit
pyshell.end(function (err) {
pyshell.end(function (err,code,signal) {
if (err) throw err;
console.log('The exit code was: ' + code);
console.log('The exit signal was: ' + signal);
console.log('finished');
console.log('finished');
});

@@ -213,2 +216,6 @@ ```

#### `.terminate(signal)`
Terminates the python script, the optional end callback is invoked if specified. A kill signal may be provided by `signal`, if `signal` is not specified SIGTERM is sent.
#### event: `message`

@@ -215,0 +222,0 @@

@@ -241,5 +241,5 @@ var should = require('should');

var pyshell = new PythonShell('exit-code.py');
pyshell.end(function (err) {
pyshell.end(function (err,code,signal) {
if (err) return done(err);
pyshell.exitCode.should.be.exactly(0);
code.should.be.exactly(0);
done();

@@ -291,2 +291,32 @@ });

});
describe('.terminate()', function () {
it('set terminated to true', function (done) {
var pyshell = new PythonShell('infinite_loop.py');
pyshell.terminate();
pyshell.terminated.should.be.true
done();
});
it('run the end callback if specified', function (done) {
var pyshell = new PythonShell('infinite_loop.py');
var endCalled = false;
pyshell.end(()=>{
endCalled = true;
})
pyshell.terminate();
pyshell.terminated.should.be.true
done();
});
it('terminate with correct kill signal', function (done) {
var pyshell = new PythonShell('infinite_loop.py');
var endCalled = false;
pyshell.end(()=>{
endCalled = true;
})
pyshell.terminate('SIGKILL');
pyshell.terminated.should.be.true;
setTimeout(()=>{pyshell.exitSignal.should.be.exactly('SIGKILL');},500);
done();
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc