FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

How to handle error when python's path is invalid? · Issue #118 · extrabacon/python-shell · GitHub

Repository navigation

How to handle error when python's path is invalid? #118

Description

            const PythonShell = require('python-shell');
            const options = {
                pythonPath: './notthepythonpath',
                scriptPath: 'scriptdir',
                args: [0, 0, 400, 400, 1, store.get('outputPath')],
                mode: 'text',
            };
            let pyshell = new PythonShell('script.py', options);
            pyshell.on('error', (err) => {
                alert(err);
            });

I've tried the callback ,and tried on('error') but both doesn't seem to catch it.

Activity

  1. Almenon commented on Apr 12, 2018

    Collaborator

    I'll have to look into that - the error event should fire for that.

    Here's the code I use in arepl-vscode:

    pyshell.childProcess.on('error', err => {
      let error:any = err; //typescript complains about type for some reason so defining to any
      this.pythonPreviewContentProvider.handleSpawnError(error.path, error.spawnargs[0], error.stack);
    })
  2. sejsingffdc commented on Oct 26, 2018

    I ran into the same problem. I believe the root cause is with this line in python-shell:

    this.childProcess = child_process_1.spawn(pythonPath, this.command, options);

    the spawn() function can throw an exception if the path is invalid (see here nwjs/nw.js#1623). It appears that spawn must have an error handler attached like this:

    spawn.on('error', function (err) {
        console.log('spawn error:', err);
    });
  3. sejsingffdc commented on Oct 26, 2018

    This code is in PythonShell's constructor.

  4. sejsingffdc commented on Nov 6, 2018

    Could it be OS dependent behavior? I'm on Mac.

  5. Almenon commented on Nov 22, 2018

    Collaborator

    @sejsingffdc nah, I have windows and it does same thing.

    I'll change the error event to also fire when the path is invalid.

    Once I finish promise support (#77) the python process will be launched via a start method which will return or reject a promise based on whether it sucessfully launched the process.

  6. added a commit that references this issue on Mar 8, 2021
    96dfae8
  7. self-assigned this
    on Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL