Julia 相当于 Python 的 schedule 包是什么?

What is the Julia equivalent to Python's schedule package?

我有一段 Python 代码想要转换成 Julia。我的 python 代码我使用 schedule 包。 Julia 中的等效项是什么,我查看了 Julia 文档中的 "Tasks and Parallel Computing" 部分,但找不到类似的内容。 Python中的代码是:

def main():
    schedule.every(0.25).seconds.do(read_modbus, 1, 1000, 100, 1)
    while True:
        schedule.run_pending()
        time.sleep(0.05)

Will a Timer work? This form of Timer calls your function in a Task 所以你需要偶尔从你的主循环中让出控制权以允许定时器任务 运行。你可以通过调用yieldsleepwait或者做IO来yield,这里我展示的是waiting on 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

我注意到 Julia was missing so I wrote one 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),只有一个阻塞调度器的实现,但应该可以添加多线程。