julia - 控制 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
。
使用Timer
s,您仍然可以继续将您的 julia 实例用于其他目的。
推荐阅读
- shell - Shell 脚本比较 .conf 值
- sql - 获取带空格的数据库名称
- python - 在 python 中构建回归时,如何为最近的数据分配更大的权重
- java - 决策树分类器在分类实例时存在问题
- java - 不使用 UsernamePasswordAuthenticationToken 的 Spring Security JWT 验证
- java - 使用 Twitter 为 Oauth 创建签名
- c++ - 带有 czmq 的 ZeroMQ 在性能测试中表现出剧烈的波动
- sql - 跨列聚合 SQL-Netezza
- laravel - 如果在获取结果集后获取数据总数,Laravel 分页会中断。知道为什么吗?
- java - 如何使用 volley 提高 android API 调用速度