Connect following disconnect fails

I’m using the python SDK to establish a connection with the hologram nova modem. Everything works well, but occasionally the connection is lost. When connection is lost, I would like to kill the existing PPP session and loop until a new one is created successfully. However, calling disconnect to ensure the previous session is disconnected, followed by connect, yields the message “Existing PPP session(s) are established by pid(s) [14158]. Please close/kill these processes first.” How can I correctly kill the previous session in the python script? Also how can I find the process id so I can kill the session with a subprocess call if necessary?

I have also gotten a network unreachable error on the second connection attempt when the initial attempt fails but doesn’t crash with the existence error.

Thanks for the help

I think that’s a bug in our disconnect function. You can try doing the CLI version of that instead hologram network disconnect which will just kill every pppd process it finds.
You can copy the underlying code from here if you want: hologram-python/hologram_network.py at master · hologram-io/hologram-python · GitHub

Thanks for the quick response!

That makes sense. I copied the code and am now able to successfully kill the process, but the Modem doesn’t seem to know. The error I’m getting is in Hologram/Network/Modem/ModemMode/PPP on _enforce_no_existing_ppp_session. The pid it requests that I kill is the one I just killed using the code you linked.

I’m connecting withe the HologramCloud class, so I’m not sure how to access the Modem directly. What can I do to clear the Modem’s ppp_session?

After reading through the repo I see that I can clear the process by calling hologram.network.disconnect() or alternatively by referencing hologram.network.modem.disconnect() directly. Now, most of the time I can loop until hologram.network.connect() returns true, which is great! However, occasionally the program seems to crash in the connect with the error:

pyroute2.netlink.exceptions.NetlinkError: (101, ‘Network is unreachable’)

Why would this happen sometimes, instead of just returning false so I can reattempt connection?

I see the same bug. any update on this?

Which version of the python SDK are you using? How long do you wait between when the PPP daemon is killed before trying to reconnect? the daemon is not instantly destroyed when you request to disconnect so it might take a few seconds before the process is actually finished terminating.