Function not repeating using function.after call consistently

Viewed 31

I have a script that displays a dashboard of the amount of shipped orders in our warehouse by calling our shipping company API every 20 seconds.

I call the functions as threads to stop them freezing the Tkinter GUI

def company1Thread():
  tSF=Thread(target=importCompany1)
  tSF.start()
def company2Thread():
  tEX=Thread(target=importCompany2)
  tEX.start()

Etc... (5 in total threads)

Then I have functions for each API call to each company

def importCompany1():
    
    try:
      conn = http.client.HTTPSConnection("")
      payload = ''
      headers = {
        'Content-Type': 'application/json',
        'StarShipIT-Api-Key': '',
        'Ocp-Apim-Subscription-Key': ''
      }
      conn.request(, payload, headers )
      res = conn.getresponse()
      
      print("Company 1 Printed", res.status, res.reason)

      window.after(20000, company1Thread)
    except: window.after(20000, company1Thread)

This can work for hours or days, but sometimes will stop updating every 20 completely while the other threads continue.

I have a feeling it is a request timeout issue or something like that, however, assumed the try/except would cover that. Is there anything else I am missing?

0 Answers
Related