[Solved] Hologram sendMessage timeout doesn't seem to work

Hi there,

Once in a while, perhaps because of bad network connectivity, hologram sendMessage calls don’t seem to complete. That’s to be expected, so I tried to include a timeout parameter in the call as per the API (but I also discovered it defaults to 5 seconds) and it doesn’t seem to throw an error or do anything after the timeout expires.

A minimal reproduce looks like running a python script:

Hologram-specific imports

from Hologram.HologramCloud import HologramCloud

hologram = HologramCloud(dict(), network='cellular')

print "Trying to send message to hologram: 10 second timeout"                                                                                                  
hologram.sendMessage("hello!", timeout=10)
print "msg sent"

And disabling the SIM card in the Hologram Dashboard:
Screenshot from 2018-03-13 17-22-30

This seems to put the python code into a busy-wait loop and the CPU usage on the scheduled core stays at 100% until the script is killed.

Is this the expected behavior of the timeout argument, and if so, what should I use to check for a failed sendMessage call after a certain period of time?

Thank you in advance :slight_smile:

EDIT: I’m not too sure if I’ve gotten the sub-forum right here, apologies if I have.

Hey Frizensami,

Our 0.7.5 release of the Hologram Python SDK fixed an issue where it could hang when a message was not sent successfully. Can you confirm that you are working with version 0.7.5?

Best,
Maiky

Hey Maiky,

I was running version 0.7.4, looks like 0.7.5 has a fix for this. I just tried to run the update script with curl -L hologram.io/python-update | bash, but I think something in the installation process isn’t working correctly because I get this error traceback when I attempt to run the same script from above:

Traceback (most recent call last):
  File "hologram_test.py", line 2, in <module>
    from Hologram.HologramCloud import HologramCloud
  File "/usr/local/lib/python2.7/dist-packages/Hologram/HologramCloud.py", line 14, in <module>
    from CustomCloud import CustomCloud
  File "/usr/local/lib/python2.7/dist-packages/Hologram/CustomCloud.py", line 15, in <module>
    from Cloud import Cloud
  File "/usr/local/lib/python2.7/dist-packages/Hologram/Cloud.py", line 13, in <module>
    from Network import NetworkManager
  File "/usr/local/lib/python2.7/dist-packages/Hologram/Network/NetworkManager.py", line 15, in <module>
    from Cellular import Cellular
  File "/usr/local/lib/python2.7/dist-packages/Hologram/Network/Cellular.py", line 14, in <module>
    from Modem import Modem
  File "/usr/local/lib/python2.7/dist-packages/Hologram/Network/Modem/__init__.py", line 2, in <module>
    from Modem import *
  File "/usr/local/lib/python2.7/dist-packages/Hologram/Network/Modem/Modem.py", line 27, in <module>
    from serial.serialutil import Timeout
ImportError: cannot import name Timeout

This is the entire output of the upgrade process:

The directory '/home/sriram/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/sriram/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: hologram-python in /usr/local/lib/python2.7/dist-packages
Collecting enum34==1.1.6 (from hologram-python)
  Downloading enum34-1.1.6-py2-none-any.whl
Requirement already up-to-date: hjson==2.0.2 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: mock==2.0.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Collecting psutil==5.3.1 (from hologram-python)
  Downloading psutil-5.3.1.tar.gz (397kB)
    100% |████████████████████████████████| 399kB 740kB/s 
Requirement already up-to-date: pyroute2==0.4.21 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Collecting pyserial==3.3 (from hologram-python)
  Downloading pyserial-3.3-py2.py3-none-any.whl (189kB)
    100% |████████████████████████████████| 194kB 555kB/s 
Requirement already up-to-date: pytest==3.0.5 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-pppd==1.0.3 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-sdk-auth==0.2.1 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-wifi==0.6.1 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyudev==0.21.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyusb==1.0.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Collecting requests==2.18.3 (from hologram-python)
  Downloading requests-2.18.3-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 534kB/s 
Collecting pbr>=0.11 (from mock==2.0.0->hologram-python)
  Downloading pbr-3.1.1-py2.py3-none-any.whl (99kB)
    100% |████████████████████████████████| 102kB 829kB/s 
Requirement already up-to-date: funcsigs>=1; python_version < "3.3" in /usr/local/lib/python2.7/dist-packages (from mock==2.0.0->hologram-python)
Requirement already up-to-date: six>=1.9 in /usr/lib/python2.7/dist-packages (from mock==2.0.0->hologram-python)
Requirement already up-to-date: py>=1.4.29 in /usr/local/lib/python2.7/dist-packages (from pytest==3.0.5->hologram-python)
Requirement already up-to-date: pycrypto==2.6.1 in /usr/lib/python2.7/dist-packages (from python-sdk-auth==0.2.1->hologram-python)
Collecting certifi>=2017.4.17 (from requests==2.18.3->hologram-python)
  Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB)
    100% |████████████████████████████████| 153kB 2.1MB/s 
Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)
Collecting urllib3<1.23,>=1.21.1 (from requests==2.18.3->hologram-python)
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 292kB/s 
Requirement already up-to-date: idna<2.6,>=2.5 in /usr/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)
Installing collected packages: enum34, psutil, pyserial, certifi, urllib3, requests, pbr
  Found existing installation: enum34 1.1.2
    Not uninstalling enum34 at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: psutil 5.0.1
    Not uninstalling psutil at /usr/lib/python2.7/dist-packages, outside environment /usr
  Running setup.py install for psutil ... done
  Found existing installation: pyserial 3.0.1
    Not uninstalling pyserial at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: certifi 2017.4.17
    Not uninstalling certifi at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: urllib3 1.21.1
    Not uninstalling urllib3 at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: requests 2.18.1
    Not uninstalling requests at /usr/lib/python2.7/dist-packages, outside environment /usr
  Found existing installation: pbr 1.8.0
    Not uninstalling pbr at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed certifi-2017.4.17 enum34-1.1.2 pbr-1.8.0 psutil-5.0.1 pyserial-3.0.1 requests-2.18.1 urllib3-1.21.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I tried to resolve this by installing the latest version of pip with pip install --upgrade pip but was only able to upgrade to an 8.x version of pip. I had to uninstall pip in the package manager with sudo apt-get purge python-pip, which brought me to pip version 9.0.1.

Now, during the upgrade process, i’m being told that all my requirements are up to date:

Requirement already up-to-date: hologram-python in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: enum34==1.1.6 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: hjson==2.0.2 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: mock==2.0.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: psutil==5.3.1 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyroute2==0.4.21 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyserial==3.3 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pytest==3.0.5 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-pppd==1.0.3 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-sdk-auth==0.2.1 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: python-wifi==0.6.1 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyudev==0.21.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pyusb==1.0.0 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: requests==2.18.3 in /usr/local/lib/python2.7/dist-packages (from hologram-python)
Requirement already up-to-date: pbr>=0.11 in /usr/local/lib/python2.7/dist-packages (from mock==2.0.0->hologram-python)
Requirement already up-to-date: funcsigs>=1; python_version < "3.3" in /usr/local/lib/python2.7/dist-packages (from mock==2.0.0->hologram-python)
Requirement already up-to-date: six>=1.9 in /usr/lib/python2.7/dist-packages (from mock==2.0.0->hologram-python)
Requirement already up-to-date: py>=1.4.29 in /usr/local/lib/python2.7/dist-packages (from pytest==3.0.5->hologram-python)
Requirement already up-to-date: pycrypto==2.6.1 in /usr/lib/python2.7/dist-packages (from python-sdk-auth==0.2.1->hologram-python)
Requirement already up-to-date: certifi>=2017.4.17 in /usr/local/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)
Requirement already up-to-date: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)
Requirement already up-to-date: urllib3<1.23,>=1.21.1 in /usr/local/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)
Requirement already up-to-date: idna<2.6,>=2.5 in /usr/lib/python2.7/dist-packages (from requests==2.18.3->hologram-python)

However, I still get the ImportError: cannot import name Timeout error message. Not really sure why this is the case.

Sorry, this looks like a conflict between

  1. My OS-level pyserial package and
  2. The pip pyserial==3.3 package.

If anyone else comes across this issue, I do recommend uninstalling pyserial on your package manager (apt) for e.g. and trying the update script again.

Hey Frizensami,

Thanks for the heads up!

Best,
Maiky

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.