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

python-shell

Package Overview
Dependencies
Maintainers
1
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.3.0 to 0.4.0

27

index.js

@@ -76,9 +76,27 @@ var EventEmitter = require('events').EventEmitter;

this.stderr.on('end', function(){
self.stderrHasEnded = true
terminateIfNeeded();
})
this.stdout.on('end', function(){
self.stdoutHasEnded = true
terminateIfNeeded();
})
this.childProcess.on('exit', function (code) {
self.exitCode = code;
terminateIfNeeded();
});
function terminateIfNeeded() {
if (!self.stderrHasEnded || !self.stdoutHasEnded || self.exitCode == null) {
return;
}
var err;
if (errorData || code !== 0) {
if (errorData || self.exitCode !== 0) {
if (errorData) {
err = self.parseError(errorData);
} else {
err = new Error('process exited with code ' + code);
err = new Error('process exited with code ' + self.exitCode);
}

@@ -90,3 +108,3 @@ err = extend(err, {

args: scriptArgs.length ? scriptArgs : null,
exitCode: code
exitCode: self.exitCode
});

@@ -98,7 +116,6 @@ // do not emit error if only a callback is used

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

@@ -105,0 +122,0 @@ util.inherits(PythonShell, EventEmitter);

5

package.json
{
"name": "python-shell",
"version": "0.3.0",
"version": "0.4.0",
"description": "Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio",

@@ -28,3 +28,4 @@ "keywords": [

"node": ">=0.10"
}
},
"license": "MIT"
}

@@ -63,2 +63,48 @@ var should = require('should');

});
it('should run multiple scripts and fail with an extended stack trace for each of them', function (done) {
var numberOfTimesToRun = 20;
for (var i = 0; i < numberOfTimesToRun; i++) {
runSingleErrorScript(end);
}
var count = 0;
function end() {
count++;
if (count === numberOfTimesToRun) {
done();
}
}
function runSingleErrorScript(callback) {
PythonShell.run('error.py', function (err, results) {
err.should.be.an.Error;
err.exitCode.should.be.exactly(1);
err.stack.should.containEql('----- Python Traceback -----');
callback();
});
}
});
it('should run multiple scripts and return output data for each of them', function (done) {
var numberOfTimesToRun = 20;
for (var i = 0; i < numberOfTimesToRun; i++) {
runSingleScript(end);
}
var count = 0;
function end() {
count++;
if (count === numberOfTimesToRun) {
done();
}
}
function runSingleScript(callback) {
PythonShell.run('echo_args.py', {
args: ['hello', 'world']
}, function (err, results) {
if (err) return done(err);
results.should.be.an.Array.and.have.lengthOf(2);
results.should.eql(['hello', 'world']);
callback();
});
}
});
});

@@ -65,0 +111,0 @@

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