<commit_before>var children = require('child_process')
var delta = require('delta')
var cadence = require('cadence')
var interrupt = require('interrupt').createInterrupter('compassion.colleague')
var coalesce = require('extant')

var Signal = require('signal')
var Destructible = require('destructible')

function Monitor () {
    this.ready = new Signal
    this.child = null
    this.destroyed = false
    this._destructible = new Destructible
    this._destructible.markDestroyed(this)
    this._destructible.addDestructor('started', this.ready, 'unlatch')
    this._destructible.addDestructor('kill', this, '_kill')
}

Monitor.prototype._kill = function () {
    if (this.child != null) {
        this.child.kill()
        this.child = null
    }
}

Monitor.prototype.run = cadence(function (async, program) {
    this._destructible.stack(async, 'run')(function (ready) {
        var argv = program.argv.slice()
        var env = JSON.parse(JSON.stringify(program.env))
        env.COMPASSION_COLLEAGUE_FD = 3
        this.child = children.spawn(argv.shift(), argv, {
            stdio: [ 'inherit', 'inherit', 'inherit', 'pipe' ],
            env: env
        })
        async(function () {
            delta(async()).ee(this.child).on('exit')
            ready.unlatch()
        }, function (exitCode, signal) {
            interrupt(exitCode == 0 || signal == 'SIGTERM', 'childExit', {
                exitCode: coalesce(exitCode),
                signal: coalesce(signal)
            })
        })
    })
    this._destructible.ready.wait(this.ready, 'unlatch')<commit_msg>Use 0, 1, 2 for fd inheritance.<commit_after>var children = require('child_process')
var delta = require('delta')
var cadence = require('cadence')
var interrupt = require('interrupt').createInterrupter('compassion.colleague')
var coalesce = require('extant')

var Signal = require('signal')
var Destructible = require('destructible')

function Monitor () {
    this.ready = new Signal
    this.child = null
    this.destroyed = false
    this._destructible = new Destructible
    this._destructible.markDestroyed(this)
    this._destructible.addDestructor('started', this.ready, 'unlatch')
    this._destructible.addDestructor('kill', this, '_kill')
}

Monitor.prototype._kill = function () {
    if (this.child != null) {
        this.child.kill()
        this.child = null
    }
}

Monitor.prototype.run = cadence(function (async, program) {
    this._destructible.stack(async, 'run')(function (ready) {
        var argv = program.argv.slice()
        var env = JSON.parse(JSON.stringify(program.env))
        env.COMPASSION_COLLEAGUE_FD = 3
        this.child = children.spawn(argv.shift(), argv, {
            stdio: [ 0, 1, 2, 'pipe' ],
            env: env
        })
        async(function () {
            delta(async()).ee(this.child).on('exit')
            ready.unlatch()
        }, function (exitCode, signal) {
            interrupt(exitCode == 0 || signal == 'SIGTERM', 'childExit', {
                exitCode: coalesce(exitCode),
                signal: coalesce(signal)
            })
        })
    })
    this._destructible.ready.wait(this.ready, 'unlatch')
{'fraction_non_alphanumeric': 0.14163498098859315, 'fraction_numerical': 0.0031685678073510772, 'mean_word_length': 2.8220338983050848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3806521', 'n_tokens_mistral': 975, 'n_tokens_neox': 927, 'n_words': 185}