LowellObservatory / NightShift

Collection of sub-modules used in the NightWatch (and other Night*) project
Mozilla Public License 2.0
1 stars 1 forks source link

Fix image grab/timeout issue #14

Open astrobokonon opened 3 years ago

astrobokonon commented 3 years ago

Downloading an image from dct-allsky failed, in the middle of grabbing the image, and things just hung.

2020-08-26 00:48:58,343 INFO     Retrieving camera image: DCTAllSky
2020-08-26 00:48:58,368 INFO     Attempting to write image to ./outputs/images/dct//allsky.jpg
2020-08-26 00:48:58,369 INFO     Retrieving image from: http://dct-allsky.lowell.edu/allsky//as20200825_125046.jpg

It hung for hours there until someone noticed, so I restarted by hand and now the errors are getting trapped properly and timing out.

2020-08-26 02:28:05,651 INFO     Username None in section DomeRoof has no password!
2020-08-26 02:28:05,652 INFO     Found the following sections in the configuration file:
2020-08-26 02:28:05,652 INFO     UpperGate HeliumCompressor Genset TelescopeBuilding UtilityYard ObservingLevel DomeRoof DCTAllSky
2020-08-26 02:28:05,652 INFO     Enabled:
2020-08-26 02:28:05,652 INFO     UpperGate HeliumCompressor Genset TelescopeBuilding UtilityYard ObservingLevel DomeRoof DCTAllSky
2020-08-26 02:28:05,653 INFO     Retrieving camera image: UpperGate
2020-08-26 02:28:05,653 INFO     Attempting to write image to ./outputs/images/dct//gate.jpg
2020-08-26 02:28:05,718 INFO     Good grab!
2020-08-26 02:28:06,219 INFO     Retrieving camera image: HeliumCompressor
2020-08-26 02:28:06,219 INFO     Attempting to write image to ./outputs/images/dct//heliumcomp.jpg
2020-08-26 02:28:06,223 INFO     HTTPConnectionPool(host='10.11.131.61', port=80): Max retries exceeded with url: /image/jpeg.cgi (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff24c90afd0>: Failed to establish a new connection: [Errno 111] Connection refused'))
2020-08-26 02:28:06,748 INFO     Retrieving camera image: Genset
2020-08-26 02:28:06,748 INFO     Attempting to write image to ./outputs/images/dct//genset.jpg
2020-08-26 02:28:06,808 INFO     Good grab!
2020-08-26 02:28:07,309 INFO     Retrieving camera image: TelescopeBuilding
2020-08-26 02:28:07,310 INFO     Attempting to write image to ./outputs/images/dct//tel_bldg.jpg
2020-08-26 02:28:12,317 INFO     HTTPConnectionPool(host='10.11.131.63', port=80): Max retries exceeded with url: /cgi-bin/video.jpg (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7ff24c8a5f50>, 'Connection to 10.11.131.63 timed out. (connect timeout=5.0)'))
2020-08-26 02:28:12,835 INFO     Retrieving camera image: UtilityYard
2020-08-26 02:28:12,835 INFO     Attempting to write image to ./outputs/images/dct//util_yard.jpg
2020-08-26 02:28:17,841 INFO     HTTPConnectionPool(host='10.11.131.64', port=80): Max retries exceeded with url: /cgi-bin/video.jpg (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7ff24c8ac450>, 'Connection to 10.11.131.64 timed out. (connect timeout=5.0)'))
2020-08-26 02:28:18,360 INFO     Retrieving camera image: ObservingLevel
2020-08-26 02:28:18,360 INFO     Attempting to write image to ./outputs/images/dct//obs_level.jpg
2020-08-26 02:28:18,406 INFO     Good grab!
2020-08-26 02:28:18,907 INFO     Retrieving camera image: DomeRoof
2020-08-26 02:28:18,908 INFO     Attempting to write image to ./outputs/images/dct//dome_roof.jpg
2020-08-26 02:28:18,967 INFO     Good grab!
2020-08-26 02:28:19,468 INFO     Retrieving camera image: DCTAllSky
2020-08-26 02:28:22,546 INFO     HTTPConnectionPool(host='dct-allsky.lowell.edu', port=80): Max retries exceeded with url: /allsky/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff24c8b8e50>: Failed to establish a new connection: [Errno 113] No route to host'))
astrobokonon commented 3 years ago

A quick look suggests that this is buried down deep in nightshift.webcam.grab_cams.simpleImageCopy, specifically here:

https://github.com/LowellObservatory/NightShift/blob/a10f73976ac456759e1653b40813ae1ab37ca007/nightshift/webcam/grab_cams.py#L91-L95

Seems like I'm just calling get (renamed to httpget in the import) from requests

astrobokonon commented 3 years ago

https://requests.readthedocs.io/en/latest/api/#requests.request suggests I can just slap a timeout= keyword in here, since requests.get is really just requests.request("GET", ...) and handle the exception appropriately (if it's not already caught earlier in the call chain that gets here).