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

keyError using example #6

Closed
mattloose opened this issue Feb 17, 2017 · 9 comments
Closed

keyError using example #6

mattloose opened this issue Feb 17, 2017 · 9 comments

Comments

@mattloose
Copy link

Hi,

Thanks for this great demo!

However - when I run it (python 3.6 or python 2.7) I get the following problems:

1 - running as is I get no result from the calculation and a console error reporting "Lost remote after 10000ms"

2 - If I instead run the python code in the background (rather than from the electron app) then fire the electron app I see the following errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gevent/greenlet.py", line 536, in run
    result = self._run(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/zerorpc/core.py", line 166, in _async_task
    bufchan.close()
  File "/usr/local/lib/python3.6/site-packages/zerorpc/channel.py", line 202, in close
    self._channel.close()
  File "/usr/local/lib/python3.6/site-packages/zerorpc/heartbeat.py", line 70, in close
    self._channel.close()
  File "/usr/local/lib/python3.6/site-packages/zerorpc/channel.py", line 138, in close
    del self._multiplexer._active_channels[self._channel_id]
KeyError: '7abdbe44-4e8b-4b0a-879f-000000000000'
Fri Feb 17 12:28:19 2017 <Greenlet at 0x105142178: <bound method ServerBase._async_task of <zerorpc.core.Server object at 0x1045b6f28>>(<zerorpc.events.Event object at 0x104fc6870>)> failed with KeyError

This looks to be something to do with the way strings are being passed around, but any suggestions? Running on OSX

@fyears
Copy link
Owner

fyears commented Feb 17, 2017

Hi.

Thanks for your interest. Sorry I don't have Macbook. So let me guess...

1

First of all, please download the repo as is. The code snippet in README.md may or may not be totally correct (it should be, but...)

It seems that the problem occurs on the python part.

(Maybe because of incorrect installation of gevent?)

run

# strongly recommend: do this inside virtualenv

# !! pay attention to this !!
pip install gevent 

pip install pyzmq
pip install future # necessary in python 2
pip install msgpack-python

pip install zerorpc

# run
python ./pycalc/api.py
## start running on tcp://127.0.0.1:4242  <- this line should show up?

Open another terminal and run

zerorpc tcp://localhost:4242 calc "1 + 1"
## connecting to "tcp://localhost:4242" <- it should show up
## 2.0 <- it should show up

I believe that, if there are any errors, you should see the errors in the above two steps.

Furthermore, open python and check whether it works:

import gevent

For example, I have to run something like sudo apt-get install libevent-dev on Ubuntu Linux.

2

And since you run python as it is, and open Electron, then maybe you can try to comment out the python subprocess codes and see if it is ok?

I mean line 10 ~ 61 in https://github.com/fyears/electron-python-example/blob/master/main.js.

Why? Because you don't need to start a subprocess of python from node.js in this case

@ar7max
Copy link
Contributor

ar7max commented Feb 17, 2017

There is another problem. After npm installed dependencies there is an "Uncaught Error: Module version mismatch. Expected 50, got 51." bindings.js:83

@mattloose
Copy link
Author

Thanks for getting back to me so quick. I also have seen the Module mismatch error...

However - all of the tests you suggest above work correctly and as expected. I see no errors. I have also commented out lines starting the python subprocess.

It looks to me that this is something more fundamental in the python node zerorpc ?

@fyears
Copy link
Owner

fyears commented Feb 17, 2017

@ar7max

When you are doing npm install, you need to specify npm_config_* as shown in here.

Pay attention to your electron version and

# Electron's version.
export npm_config_target=1.2.3

Then

rm -rf ~/.node-gyp
rm -rf ~/.electron-gyp
rm -rf ./node_modules

And try npm install again.

@mattloose

Very "interesting"... And I get confused... 🙁

Maybe your node.js code could not communicate with python server correctly????

How about this:

  1. run standalone python server python pycalc/api.py

  2. use another clean node.js environment, npm install zerorpc, then run line 1 ~ 12 in renderer.js in node.js cli. As you can see, the only thing it does is to call echo() function defined in the python part.

If, step 2 goes well, also try to invoke calc() from pure node.js environment (you know how to do it 😜). If it also goes well, then we know that some problems occur while installing node.js libraries for electron, which needs your further investigation.

@fyears
Copy link
Owner

fyears commented Feb 18, 2017

@ar7max

One more thing, when you are in Windows, checkout the syntax about setting environment variables.

export npm_config_target=1.4.15 # electron version
export npm_config_arch=x64
export npm_config_target_arch=x64
export npm_config_disturl=https://atom.io/download/electron
export npm_config_runtime=electron
export npm_config_build_from_source=true

npm config ls

The above export K=V syntax is available for Linux/OS X, and git-bash and mingw bash, etc, on Windows. But it's NOT available on Windows cmd.exe or PowerShell. If you are in cmd.exe or PowerShell, use set K=V syntax as shown here.

@ar7max
Copy link
Contributor

ar7max commented Feb 18, 2017

@fyears, I'm using Arch Linux with Python 3.6.

  1. Electron side works after setting env vars and re-installing node modules;
  2. Python 3.6 side works fine after removing pypiwin32 dependency and running pip install again.

@mattloose
Copy link
Author

Not quite sure how I have fixed this, but a complete rebuild of electron and cleaning up of node seems to have worked. Thanks for the cool demo!

@fyears
Copy link
Owner

fyears commented Feb 27, 2017

@ar7max By the way, may you consider removing my personal blog repo from your account? If necessary you may just fork the current dev repo instead of the blog repo. Thank you! :-)

@ar7max
Copy link
Contributor

ar7max commented Feb 27, 2017

@fyears, done.

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

3 participants