Made a simple script that starts when you run PI. It consists of an infinite loop that sends parameters to the server.

The problem is that after an hour or two, everything stalls, although the malinka is not frozen, and the demon even seems to be hanging in memory.

What could be the problem?

while 1: doc = urllib.request.urlopen("адрес") time.sleep(600) 

I use raspberryPi 3 .

  • 2
    Expand your concepts: "everything stalls" and "like a demon even hangs" - in more detail. - 0xdb
  • Infinite loop seems to be written through True ? while True: pass - Shihkauskas
  • You just have incorrect logging and error handling done - Andrio Skur
  • there is no difference, everything will be reduced to bool. - Andrio Skur
  • 3
    urllib.request.urlopen("адрес", timeout=30) and then it will be seen - andreymal

1 answer 1

The solution was error handling.

 import time, requests while True: try: requests.get('адрес', timeout=(10)) except requests.exceptions.ReadTimeout: print('Oops. Read timeout occured') except requests.exceptions.ConnectTimeout: print('Oops. Connection timeout occured!') except requests.exceptions.HTTPError as err: print('Oops. HTTP Error occured') except requests.exceptions.ConnectionError: print('Oops. Connection error!') time.sleep(60)