在 Julia lang 中控制资源使用

Controlling resource usage in Julia lang

我想构建一个软件,每隔一段时间就会 运行 自动对 Julia 中磁盘中的大量文件进行排序。

我试着用下面的代码来做,但是耗尽了我的资源。

while true
// if it's 6 O'clock in the morning, runs function for batch processing
end

如何限制资源使用?

您可以使用 Timer 事件而不是循环。您需要做的就是定义一个回调函数,该函数接受一个 Timer 参数并完成您想要的工作。

julia> begin
         myfun(timer) = println("Sort Files")
         t = Timer(myfun, 2, interval = 0.2) # after 2 seconds the task will run for each 0.2 seconds interval
         wait(t) # the timer events will trigger forever if you want to stop the events you should call close(t) somewhere in the future
       end

您可以使用 close(timer) 根据条件停止函数中的计时器,或者稍后通过调用 close(t) 可以访问 t.[=18 的其他地方=]

有了 Timers,您仍然可以继续将 julia 实例用于其他目的。