extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.11k stars 224 forks source link

[Error] This socket has been ended by the other party #92

Open rekkisomo opened 7 years ago

rekkisomo commented 7 years ago

I'm running into an issue when running a Python Script.

I have a script which asks for user input, then returns a string in console. But when sending a message, it gives this stacktrace:

reason: Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:355:12)
    at PythonShell.send (/marshmallow/node_modules/python-shell/index.js:205:16)
    at /marshmallow/ctrl/mod.js:114:27
    at Promise (<anonymous>)
    ...

Here is my code

let PY = require('python-shell')
global.smarts = {
  SHELL: new PY('pyBot/chatbot.py', {
    mode: 'text',
    args: ['--save_dir', 'pyBot/models/xhavier']
  }),
  write: (m) => {
    return new Promise(function(s) {
      let msg

      global.debug.check('[ACCESS] Neural Network')
      global.smarts.SHELL.send(m) // Here

      // Doesn't continue below here.
      global.smarts.SHELL.on('message', (d) => {
        global.debug.check(d)
        if(!d.startsWith('>')) {
          msg = d
        }
      })

      ...
    })
  }
}
jderiz commented 7 years ago

No one any Idea?

Im getting the same error

Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:294:12)
    at PythonShell.send (/Users/jd/PycharmProjects/gekko/node_modules/python-shell/index.js:205:16)
    at Base.strategy.update (/Users/jd/PycharmProjects/gekko/strategies/custom.js:72:11)
    at Base.bound [as update] (/Users/jd/PycharmProjects/gekko/node_modules/lodash/dist/lodash.js:729:21)
    at Base.propogateTick (/Users/jd/PycharmProjects/gekko/plugins/tradingAdvisor/baseTradingMethod.js:262:8)
    at Base.bound [as propogateTick] (/Users/jd/PycharmProjects/gekko/node_modules/lodash/dist/lodash.js:729:21)
    at _.after (/Users/jd/PycharmProjects/gekko/plugins/tradingAdvisor/baseTradingMethod.js:218:18)
    at /Users/jd/PycharmProjects/gekko/node_modules/lodash/dist/lodash.js:5144:23
    at Object.talibResultHander (/Users/jd/PycharmProjects/gekko/plugins/tradingAdvisor/baseTradingMethod.js:230:7)
    at talibCallback (/Users/jannisderiz/PycharmProjects/gekko/core/talib.js:13:9)

the error only occurs tho when I make the shell instance in another method then the actual data sending