Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments get passed to Node when launched from Python Interactive in VSCode #149

Closed
Clocktown opened this issue Nov 24, 2018 · 3 comments
Closed

Comments

@Clocktown
Copy link

Clocktown commented Nov 24, 2018

System Info

Windows 10 Pro 64 Bit
Anaconda3, Python 3.7, 64 Bit
orca installed through conda

Expected behaviour

Running orca using Python subprocess module actually runs orca.

Actual behaviour

Arguments are passed to node instead, but only if run inside a Visual Studio Code "Python Interactive" Pane (Jupyter Server), and in no other situation.

Long Version

I have a very weird issue, and it might not be orca's fault at all, but I'm still posting this looking for clues.

When I run the following python code:

import subprocess
res = subprocess.run(
    args=[<path_to_orca>, '--help'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

print(res.args)
print(res.stdout)
print(res.stderr)
print(res.returncode)

It works fine if run in a regular Python REPL, if run as a file with Python, through a jupyter notebook or jupyter qtconsole. It works, as it should. But if I open a "Python Interactive" Pane in Visual Studio Code (through their Python extension) -- which runs a Jupyter Server anyways -- this command will instead invoke what appears to be node --help. I tried different arguments, and I always get output as if I'd have launched node instead of orca. This unfortunately breaks the plotly.io capabilities, as long as it's run in this Interactive Pane. Note that I could not reproduce this with other executables, e.g. launching VS Code itself like this does what it is supposed to.

My guess is that some sketchy electron/node stuff happens here. Both VSCode and orca use electron after all. But as I already mentioned, if I launch Code itself with this, it works. I could only produce this problem with orca.

I will also post an issue at the VSCode Python extension GitHub, as I really have no clue what is at fault here.
Edit: Related issue: https://github.com/Microsoft/vscode-python/issues/3455

@jonmmease
Copy link
Contributor

Hi @Clocktown,

I am able to reproduce this on MacOS, and you're right that it's a really weird issue. I think I tracked down the culprit. I started by dumping out all of the environment variables that are set in the VSCode/Python Interactive session:

import os
print('\n'.join(os.environ))
__CF_USER_TEXT_ENCODING
TMPDIR
HOME
SHELL
Apple_PubSub_Socket_Render
SSH_AUTH_SOCK
PATH
LOGNAME
XPC_SERVICE_NAME
COMMAND_MODE
USER
XPC_FLAGS
GOOGLE_API_KEY
VSCODE_NLS_CONFIG
VSCODE_NODE_CACHED_DATA_DIR
VSCODE_LOGS
VSCODE_IPC_HOOK
VSCODE_PID
CONDA_SHLVL
PWD
SHLVL
_
AMD_ENTRYPOINT
PIPE_LOGGING
VERBOSE_LOGGING
VSCODE_IPC_HOOK_EXTHOST
VSCODE_HANDLES_UNCAUGHT_ERRORS
VSCODE_LOG_STACK
VSCODE_LOG_LEVEL
CRASH_REPORTER_START_OPTIONS
ELECTRON_RUN_AS_NODE
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL
CONDA_PREFIX
CONDA_DEFAULT_ENV
PYTHONUNBUFFERED
PYTHONIOENCODING
JPY_PARENT_PID
TERM
CLICOLOR
PAGER
GIT_PAGER
MPLBACKEND

And the ELECTRON_RUN_AS_NODE variable caught by eye. This is set to 1 here:

print(os.environ['ELECTRON_RUN_AS_NODE']) 
1

Here are the docs that I could find for it https://electronjs.org/docs/api/environment-variables#electron_run_as_node

ELECTRON_RUN_AS_NODE
Starts the process as a normal Node.js process.

If I delete this environment variable, all is well:

del os.environ['ELECTRON_RUN_AS_NODE']
import subprocess
res = subprocess.run(
    args=['/Applications/orca.app/Contents/MacOS/orca', '--help'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

print(res.stdout.decode())
Plotly's image-exporting utilities

  Usage: orca [--version] [--help]  []

  Available commands:
  - graph [or plotly-graph, plotly_graph]
    Generates an image of plotly graph from inputted plotly.js JSON attributes.
    For more info, run `orca graph --help`.
  - serve [or server]
    Boots up a server with one route per available export component
    For more info, run `orca serve --help`.

I don't really know what this variable is for, so I don't know if deleting it is going to break something else in VSCode. plotly.py already clears the NODE_OPTIONS environment variable because it causes a segfault in the version of electron that orca is using, so it would be fine from the plotly.py side to clear ELECTRON_RUN_AS_NODE as well.

Any thoughts @rchiodo?

@Clocktown
Copy link
Author

Clocktown commented Dec 2, 2018

@jonmmease Thanks for your detailed comment!
I verified this on Windows and indeed, that environment variable is the culprit. Which means we now have a working work-around at least.
I also think clearing the variable from the plotly.py is the way to go, maybe a clear and restore around the commands that call orca.

@jonmmease
Copy link
Contributor

Closing in favor of plotly/plotly.py#1293 and https://github.com/Microsoft/vscode-python/issues/3455 since the issue is out of the control of orca itself (when ELECTRON_RUN_AS_NODE is set, orca doesn't get invoked at all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants