Julia lang中的资源使用控制

Julia lang中的资源使用控制,julia,daemon,Julia,Daemon,我想构建一个每隔一段时间自动运行一次的软件,以便对Julia磁盘中的大量文件进行排序 我试着用下面的代码来做,但是消耗了我的资源 while true // if it's 6 O'clock in the morning, runs function for batch processing end 如何限制资源使用?您可以使用事件而不是使用循环。您所需要做的就是定义一个回调函数,该函数接受一个Timer参数并执行您想要的任务 julia> begin myfun(t

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

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

while true
// if it's 6 O'clock in the morning, runs function for batch processing
end
如何限制资源使用?

您可以使用事件而不是使用循环。您所需要做的就是定义一个回调函数,该函数接受一个
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
的地方来停止计时器


使用
Timer
s,您仍然可以继续将julia实例用于其他目的。

下添加
sleep(0.1)
,而true
可能是最简单的解决方案。您的解决方案很简单。对于生产系统,我建议使用操作系统内置的工具,例如Linux上的
crontab
。从长远来看,这通常更为稳健。