Python Forum

Full Version: Python continues after CTRL-C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a programm running continious controlling the heatpump, fan and air-inlet to control the climate. This programm runs for more than a year now, but twice there the programm stopped running without an error. After a CTRL-C it proceeds. I found the code stopped in the included part of te code.

def read_weergegevens(_orig_sens_buiten, _orig_sens_max_buiten, _orig_sens_min_buiten, _orig_sens_rv_buiten,_orig_sens_i_buiten ):
    try:
       _var_response = requests.get("https://www.weerstationtzandt.nl/realtime.txt")
       _var_weer = csv.reader(_var_response.text.strip().split('\n'),delimiter =' ')
       for _var_weergegevens in _var_weer:
          _sens_buiten = float(_var_weergegevens[2])
          _sens_max_buiten = float(_var_weergegevens[26])
          _sens_min_buiten = float(_var_weergegevens[28])
          _sens_rv_buiten = float(_var_weergegevens[3])
          _sens_press_buiten = float(_var_weergegevens[10]) 
          _sens_i_buiten = _calc_enthalpy(_sens_buiten,_sens_rv_buiten,_sens_press_buiten/10)
          return _sens_buiten, _sens_max_buiten, _sens_min_buiten, _sens_rv_buiten , _sens_i_buiten
    except:
       return _orig_sens_buiten, _orig_sens_max_buiten, _orig_sens_min_buiten, _orig_sens_rv_buiten , _orig_sens_i_buiten
This piece of programm reads a frequently updated online file from nearby weatherstation and collects data from it.

What can cause this behaviour and how can i prevent it.
From the documentation of the Requests package.
Quote:Timeouts
You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely:

 requests.get('https://github.com/', timeout=0.001)
The program did not stop running, it was waiting for the get() to complete. The requests.get must be catching the ctrl+c KeyboardInterrupt exception and exiting the function call.
Thanks for your answer. This must be the solution. I've modified the programm.