Python Forum
TDMA scheduling help please - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: TDMA scheduling help please (/thread-26098.html)



TDMA scheduling help please - cyborg_8274 - Apr-21-2020

Hello, I was trying to implement TDMA scheduling but i dont know how to make a job sleep for certain time until some other job gets executed. For example i want job 1 to execute for 3 sec then job 2 for 3 sec then job3 for 3 secs. But the problem is job gets executed every t seconds. i want the first job to initiate again when all the jobs are finished. so i could not do it, therefore i created global i so that it switches to next job. but can someone help me do it without global 'i'.

This is the code i wrote
import schedule
import time
from datetime import datetime
global i
i = 0
def job1(i):
    print("a_CH1.append(N_message[0].pop(", str(i), ")", str(datetime.now()))

def job2():
    #i = 0
    global i
    i = i+1
    job1(i)

def nothing():
    time.sleep(5)

#schedule.every(10).seconds.do(job1)
schedule.every(2).seconds.do(job2)
schedule.every(2).seconds.do(nothing)
#schedule.every(10).seconds.do(job1)

while 1:
    schedule.run_pending()
    #schedule.run_all()
    time.sleep(1)

schedule.clear()