Python Forum
Python continues after CTRL-C
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python continues after CTRL-C
#1
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.
Reply
#2
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.
kjbolhuis likes this post
Reply
#3
Thanks for your answer. This must be the solution. I've modified the programm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  waiting for barcode scanner output, while main program continues to run lightframe109 3 4,665 Sep-03-2020, 02:19 PM
Last Post: DeaD_EyE
  Ctrl-b 09 sunabe_97 0 31,399 Aug-01-2019, 01:19 AM
Last Post: sunabe_97
  Popen - How can I read data before CTRL+C command is issued maffaz 13 10,306 Jun-28-2018, 09:18 AM
Last Post: maffaz
  Help with code Python for "Ctrl+S" karlo_ds 1 3,104 May-28-2018, 11:22 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020