diff --git a/lib/widget.js b/lib/widget.js index c413996..7b9e5c0 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -360,16 +360,25 @@ function Screen(options) { this._maxListeners = Infinity; - if (this.options.handleUncaughtExceptions !== false) { - process.on('uncaughtException', function(err) { - reset(); - if (err) console.error(err.stack ? err.stack + '' : err + ''); - return process.exit(1); - }); - } + Screen.total++; - process.on('SIGTERM', function() { - return process.exit(0); + process.on('uncaughtException', function(err) { + if (process.listeners('uncaughtException').length > Screen.total) { + return; + } + reset(); + err = err || new Error('Uncaught Exception.'); + console.error(err.stack ? err.stack + '' : err + ''); + return process.exit(1); + }); + + ['SIGTERM', 'SIGINT', 'SIGQUIT'].forEach(function(signal) { + process.on(signal, function() { + if (process.listeners(signal).length > Screen.total) { + return; + } + return process.exit(0); + }); }); process.on('exit', function() { @@ -398,6 +407,8 @@ function Screen(options) { Screen.global = null; +Screen.total = 0; + Screen.prototype.__proto__ = Node.prototype; Screen.prototype.type = 'screen';