I want to repeat a function very 2 minutes on a list and move every time one element further of the list. I use the 'schedule' to do the task. The script is the following:
if __name__ == '__main__':
machines_queue=[[...],[...],...] # list of the sublists
global counter
counter= 0
def job(sub_list):
somefunction(sub_list) # here I want each 2 min iteration a sublist from machine_queue further
counter= counter +1 # here is pop the Error on the counter
print("I'm working...")
schedule.every(1).minutes.do(job,sub_list= machines_queue[counter])
print(counter)
while True :
schedule.run_pending()`
The first time it goes well , them I get an on the counter this Error:
"UnboundLocalError: local variable 'counter' referenced before assignment."
I don't understand because I set before the variable as global so I don't get the scope issue.
If you have an idea please .... :) Thank you in advance for your help