<commit_before>'use strict';

const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const EventEmitter = require('events');

const logger = require('../../shared/logger');
const RpcChannel = require('../../shared/rpc-channel');

module.exports = class WorkerClient extends EventEmitter {
  constructor() {
    super();

    this.workerProcess = null;
    this.rpc = RpcChannel.create('#worker', this.send.bind(this), this.on.bind(this));
  }
  reloadWorker() {
    logger.debug('WorkerWrapper: reloading worker');

    if (this.workerProcess !== null) {
      this.workerProcess.kill();
      this.workerProcess = null;
    }

    this.loadWorker();
  }
  loadWorker() {
    logger.debug('WorkerWrapper: loading worker');

    const workerPath = path.join(__dirname, '../../worker/index.js');
    if (!fs.existsSync(workerPath))
      throw new Error('can\'t execute plugin process');

    this.workerProcess = cp.fork(workerPath, [], {
      execArgv: ['--optimize_for_size', '--gc_global', '--always_compact'],
      silent: true
    });

    // Workaround for Electron 1.3.4's strange stdio redirection
    this.workerProcess.stdout.on('data', process.stdout.write);
    this.workerProcess.stderr.on('data', process.stdout.write);

    this.workerProcess.on('message', (msg) => this._handleWorkerMessage(msg));
  }
  send(channel, payload) {
    this.workerProcess.send({ channel, payload });
  }
  _handleWorkerMessage(msg) {
    const { channel, payload } = msg;
    this.emit(channel, payload);
  }
};<commit_msg>Fix log messages not printed on macOS<commit_after>'use strict';

const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const EventEmitter = require('events');

const logger = require('../../shared/logger');
const RpcChannel = require('../../shared/rpc-channel');
const lo_assign = require('lodash.assign');

module.exports = class WorkerClient extends EventEmitter {
  constructor() {
    super();

    this.workerProcess = null;
    this.rpc = RpcChannel.create('#worker', this.send.bind(this), this.on.bind(this));
  }
  reloadWorker() {
    logger.debug('WorkerWrapper: reloading worker');

    if (this.workerProcess !== null) {
      this.workerProcess.kill();
      this.workerProcess = null;
    }

    this.loadWorker();
  }
  loadWorker() {
    logger.debug('WorkerWrapper: loading worker');

    const workerPath = path.join(__dirname, '../../worker/index.js');
    if (!fs.existsSync(workerPath))
      throw new Error('can\'t execute plugin process');

    const workerOptions = {
      execArgv: ['--optimize_for_size', '--gc_global', '--always_compact'],
    };

    if (process.platform === 'win32') {
      this.workerProcess = cp.fork(workerPath, [], lo_assign(workerOptions, {
        silent: true
      }));

      // Workaround for Electron 1.3.4's strange stdio redirection
      this.workerProcess.stdout.on('data', process.stdout.write);
      this.workerProcess.stderr.on('data', process.stdout.write);
    } else {
      this.workerProcess = cp.fork(workerPath, [], workerOptions);
    }

    this.workerProcess.on('message', (msg) => this._handleWorkerMessage(msg));
  }
  send(channel, payload) {
    this.workerProcess.send({ channel, payload });
  }
  _handleWorkerMessage(msg) {
    const { channel, payload } = msg;
    this.emit(channel, payload);
  }
};
{'fraction_non_alphanumeric': 0.16548463356973994, 'fraction_numerical': 0.002364066193853428, 'mean_word_length': 3.5619946091644206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7135767', 'n_tokens_mistral': 1021, 'n_tokens_neox': 999, 'n_words': 207}