File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed
Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ export class PythonShell extends EventEmitter{
145145 if ( ! self . stderrHasEnded || ! self . stdoutHasEnded || ( self . exitCode == null && self . exitSignal == null ) ) return ;
146146
147147 let err :PythonShellError ;
148- if ( errorData || ( self . exitCode && self . exitCode !== 0 ) ) {
148+ if ( self . exitCode && self . exitCode !== 0 ) {
149149 if ( errorData ) {
150150 err = self . parseError ( errorData ) ;
151151 } else {
Original file line number Diff line number Diff line change 1+ # logging example taken from https://docs.python.org/3/howto/logging-cookbook.html
2+ # Note that logging logs to stderr by default
3+
4+ import logging
5+
6+ # set up logging to file - see previous section for more details
7+ logging .basicConfig (level = logging .DEBUG )
8+ # define a Handler which writes INFO messages or higher to the sys.stderr
9+ console = logging .StreamHandler ()
10+ console .setLevel (logging .INFO )
11+ # add the handler to the root logger
12+ logging .getLogger ('' ).addHandler (console )
13+
14+ # Now, we can log to the root logger, or any other logger. First the root...
15+ logging .info ('Jackdaws love my big sphinx of quartz.' )
16+
17+ # Now, define a couple of other loggers which might represent areas in your
18+ # application:
19+
20+ logger1 = logging .getLogger ('myapp.area1' )
21+ logger2 = logging .getLogger ('myapp.area2' )
22+
23+ logger1 .debug ('Quick zephyrs blow, vexing daft Jim.' )
24+ logger1 .info ('How quickly daft jumping zebras vex.' )
25+ logger2 .warning ('Jail zesty vixen who grabbed pay from quack.' )
26+ logger2 .error ('The five boxing wizards jump quickly.' )
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ describe('PythonShell', function () {
296296 done ( ) ;
297297 } ) ;
298298 } ) ;
299- it ( 'should emit error when error is written to stderr ' , function ( done ) {
299+ it ( 'should emit error when the program exits because of an unhandled exception ' , function ( done ) {
300300 let pyshell = new PythonShell ( 'error.py' ) ;
301301 pyshell . on ( 'error' , function ( err ) {
302302 err . message . should . be . equalOneOf ( 'ZeroDivisionError: integer division or modulo by zero' , 'ZeroDivisionError: division by zero' ) ;
@@ -305,6 +305,15 @@ describe('PythonShell', function () {
305305 done ( ) ;
306306 } ) ;
307307 } ) ;
308+ it ( 'should NOT emit error when logging is written to stderr' , function ( done ) {
309+ let pyshell = new PythonShell ( 'stderrLogging.py' ) ;
310+ pyshell . on ( 'error' , function ( err ) {
311+ done ( new Error ( "an error should not have been raised" ) ) ;
312+ } ) ;
313+ pyshell . on ( 'close' , function ( ) {
314+ done ( ) ;
315+ } )
316+ } ) ;
308317 } ) ;
309318
310319 describe ( '.parseError(data)' , function ( ) {
You can’t perform that action at this time.
0 commit comments