Skip to content

Support for running in worker threads #32

@OmgImAlexis

Description

@OmgImAlexis

With the default options the following doesn't work.

const python = pythonBridge();

Instead we get the following error. If I set stdio to ['ignore', 'pipe', 'pipe'] it works without an issue. It'd be nice to either detect the worker thread and use different defaults or catch the error and show a nicer message.

TypeError [ERR_INVALID_OPT_VALUE]: The value "WritableWorkerStdio {
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: false,
    ended: false,
    finished: false,
    destroyed: false,
    decodeStrings: false,
    defaultEncoding: 'utf8',
    length: 97,
    writing: true,
    corked: 0,
    sync: false,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: [Function],
    writelen: 97,
    bufferedRequest: null,
    lastBufferedRequest: null,
    pendingcb: 1,
    prefinished: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: false,
    bufferedRequestCount: 0,
    corkedRequestsFree: {
      next: null,
      entry: null,
      finish: [Function: bound onCorkedFinish]
    }
  },
  writable: true,
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  [Symbol(kPort)]: MessagePort {
    active: true,
    refed: true,
    _events: [Object: null prototype] {
      newListener: [Function],
      removeListener: [Function],
      message: [Function]
    },
    _eventsCount: 3,
    [Symbol(kWaitingStreams)]: 1
  },
  [Symbol(kName)]: 'stdout',
  [Symbol(kWritableCallbacks)]: [ [Function: bound onwrite] ]
}" is invalid for option "stdio"
    at internal/child_process.js:996:13
    at Array.reduce (<anonymous>)
    at getValidStdio (internal/child_process.js:922:17)
    at ChildProcess.spawn (internal/child_process.js:340:11)
    at Object.spawn (child_process.js:535:9)
    at Function.pythonBridge (/Users/xo/code/scratch/node_modules/python-bridge/index.js:22:28)
    at PostProcessor.<anonymous> (/Users/xo/code/scratch/workers/post-processor.ts:91:24)
    at step (/Users/xo/code/scratch/workers/post-processor.ts:50:23)
    at Object.next (/Users/xo/code/scratch/workers/post-processor.ts:31:53)
    at /Users/xo/code/scratch/workers/post-processor.ts:25:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/xo/code/scratch/workers/post-processor.ts:21:12)
    at PostProcessor.guessit (/Users/xo/code/scratch/workers/post-processor.ts:96:16)
    at /Users/xo/code/scratch/workers/post-processor.ts:78:29
    at Array.map (<anonymous>)
    at PostProcessor.<anonymous> (/Users/xo/code/scratch/workers/post-processor.ts:77:36)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions