How to use the python-shell.PythonShell function in python-shell

To help you get started, we’ve selected a few python-shell examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github senthilchandrasegaran / textplorer / textplorer.js View on Github external
app.post('/infoContent', function(req, res) {
    // invoke this just once, and send all the data over to the client.
    // This will make the code more responsive.
    // var infoContentParams = req.body;
    var pyShell = new PythonShell('infoContent.py', options)
    // pyShell.send(req.body.data);
    // send the transcript text to the python shell
    pyShell.send(outputtrans.target);
    pyShell.on('message', function(message) {
        infoContentDict = message
        console.log(infoContentDict)
        res.status(200).send({data: infoContentDict});
        // res.send(200, {data: infoContentDict});
        // outputInfoContent.target = infoContentParams.infoContent;
    });
    pyShell.end(function(err) {
        if (err) throw err;
    });
});
github nischi / MMM-Face-Reco-DNN / node_helper.js View on Github external
'--method=' + this.config.method,
        '--detectionMethod=' + this.config.detectionMethod,
        '--interval=' + this.config.checkInterval,
        '--output=' + this.config.output,
        '--extendDataset=' + extendedDataset,
        '--dataset=' + this.config.dataset,
        '--tolerance=' + this.config.tolerance
      ],
    };

    if (this.config.pythonPath != null && this.config.pythonPath !== '') {
      options.pythonPath = this.config.pythonPath;
    }

    // Start face reco script
    self.pyshell = new PythonShell(
      'modules/' + this.name + '/tools/facerecognition.py',
      options
    );

    // check if a message of the python script is comming in
    self.pyshell.on('message', function(message) {
      // A status message has received and will log
      if (message.hasOwnProperty('status')) {
        console.log('[' + self.name + '] ' + message.status);
      }

      // Somebody new are in front of the camera, send it back to the Magic Mirror Module
      if (message.hasOwnProperty('login')) {
        console.log(
          '[' +
            self.name +
github hanhdt / esp32-flash-tool / src / main / flash_image.js View on Github external
'--baud', params.baudRate,
      '--before', params.before,
      '--after', params.after,
      'write_flash', params.compress,
      '--flash_mode', params.flashMode,
      '--flash_freq', params.flashFreq,
      '--flash_size', params.flashSize,
      params.initialOTAIndex, params.initialOTADataBin,
      params.bootloaderIndex, params.bootloaderBin,
      params.partitionsTableIndex, params.partitionsBin,
      params.factorySerialIndex, params.factorySerialBin,
      params.appIndex, params.appBin
    ]
  }

  const pyShell = new PythonShell('esptool.py', options)

  pyShell.on('message', (message) => {
    const messageArray = message.split('\r')
    messageArray.forEach((messageItem) => {
      const msg = { id: uuidv4(), data: messageItem }
      mainWindow.webContents.send('flashing-progress-updated', msg)
    })
  })

  pyShell.end((err, code, signal) => {
    if (err) {
      mainWindow.webContents.send('flashing-progress-completed', 1, null)
      throw err
    }
    mainWindow.webContents.send('flashing-progress-completed', code, signal)
  })
github jean-emmanuel / open-stage-control / src / server / midi.js View on Github external
constructor() {

        var pythonPath = settings.read('midi').filter(x=>x.includes('path=')).map(x=>x.split('=')[1])[0]

        this.py = new PythonShell('python/midi.py', Object.assign({
            args: [
                settings.read('debug') ? 'debug' : '',
                ...settings.read('midi')
            ],
            pythonPath
        }, pythonOptions))

    }
github eouia / MMM-GroveGestures / node_helper.js View on Github external
job: function(config) {
    this.config = config
    var map = this.config.gestureMapFromTo
    var py = path.resolve(__dirname, "py", "gesture_print.py")
    var option = {
      mode: "text",
      pythonPath:this.config.pythonPath,
      pythonOptions: ['-u'],
    }
    this.shell = new PythonShell(py, option)
    this.shell.on("message", (message)=>{
      this.log("[GESTURE] ORIGIN:" + message)
      var gesture = null
      gesture = (map.hasOwnProperty(message)) ? map[message] : null
      if (gesture) {
        this.gestureProcess(gesture)
      }
    })
    this.shell.on("error", (message)=>{
      this.shell.end()
      if (!message.traceback.search("KeyboardInterrupt")) {
        this.log(message)
      } else {
        this.log("Keyboard Interrupted")
      }
      this.log("[GESTURE] Gesture script is finished.")

python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio

MIT
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis