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

Is it possible to have two nodes created in one Notebook? #27

Open
pitosalas opened this issue Jul 3, 2019 · 7 comments
Open

Is it possible to have two nodes created in one Notebook? #27

pitosalas opened this issue Jul 3, 2019 · 7 comments

Comments

@pitosalas
Copy link

I am still trying to figure out the threading model of this approach.

@wolfv
Copy link
Member

wolfv commented Jul 3, 2019

Hi, I think it would be more common to have one node per notebook (maybe the node should actually be started automatically with jupyter-ros...)

But you can definitely have more than one subscriber (runs async in it's own thread) or publisher in the same notebook. For publisher, I had a small decorator to run the publisher in a thread so that you can do something like:

@rate(10)
rospy.publish("/mytopic", my_msg)

but this part of the code isn't ready yet. If you want to work on something like this that would be awesome.

What's your use case for two nodes?

@pitosalas
Copy link
Author

pitosalas commented Jul 3, 2019 via email

@pitosalas
Copy link
Author

Any response to these questions. A clarificaiton of the threading and node creation model would be very useful.

@wolfv
Copy link
Member

wolfv commented Jul 8, 2019

yeah so this would be most simple to do in either two seperate notebooks (very convenient with JupyterLab since you can just create two tabs and put them next to each other) or you can open two Notebooks in two browser tabs.

Also you don't need two nodes for a subscriber and publisher.
You can just create the subscriber in the notebook first, and then later create the publisher.
The rospy subscriber automatically runs in a (Python) thread.

However, the publisher doesn't. You need to manually create a thread, or use the following magic (that has not yet been released):

https://github.com/RoboStack/jupyter-ros/blob/master/jupyros/ipy.py

That would allow you to create a cell like this:

%thread_cell

for i in range(0, 1000):
    print("Hello from a thread")
    rospy.publish("...")

But it hasn't been released because, IIRC, there were some problems. If you have some PR to make this functionality better that would be awesome! :)
w

@pitosalas
Copy link
Author

pitosalas commented Jul 8, 2019 via email

@wolfv
Copy link
Member

wolfv commented Jul 9, 2019

As far as I know you also can't have two nodes in a single python script ... So it's not even a limitation of Jupyter, but rather of rospy that you need two python processes for two real nodes.

@pitosalas
Copy link
Author

pitosalas commented Jul 9, 2019 via email

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