What is the Julia equivalent for a Python schedule?

I have a snippet of Python code that needs to be converted to Julia. I am python code I use schedule package. Which is equivalent in Julia, I looked through the "Tasks and Parallel Computing" part in the Julia documentation, but I cannot find something like that. Code in Python:

def main():
    schedule.every(0.25).seconds.do(read_modbus, 1, 1000, 100, 1)
    while True:
        schedule.run_pending()
        time.sleep(0.05)
+4
source share
2 answers

Will it work Timer? This form Timercalls your function in Task, so you need to periodically call control from your main loop to allow the timer task to run. You can get by calling yield, sleep, waitor doing the IO, here I show waiting on the timer.

tstart = time()
ncalls = 0
read_modbus() = (global ncalls+=1;@show (time()-tstart)/ncalls,ncalls)
t=Timer((timer)->read_modbus(),0,0.25)

while true
    wait(t) # wait for timer to go off
    println("mainloop $ncalls")
end
+5

, Julia , https://github.com/scls19fr/ExtensibleScheduler.jl

.

using ExtensibleScheduler

function read_modbus(p1, p2, p3, p4)
    println("Read_modbus with $p1 $p2 $p3 $p4")
end

sched = BlockingScheduler()

add(sched, Action(read_modbus, 1, 1000, 100, 1), Trigger(Dates.Millisecond(250)))

run(sched)

, , .

(2017-12) , .

+1

Source: https://habr.com/ru/post/1687442/


All Articles