HelloWorld
HelloWorld

Reputation: 1073

Controlling resource usage in Julia lang

I want to build a software that will run every once in a while, automatically, to sort significant number of files sitting in my disk in Julia.

I tried to do it with the following code, but eats up my resources.

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

How can I limit the resource usage?

Upvotes: 1

Views: 115

Answers (1)

hckr
hckr

Reputation: 5583

You can use Timer events instead of using a loop. All you need to do is to define a callback function that takes a Timer argument and does the job you want.

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

You can stop the timer in your function based on a condition using close(timer), or just later on by calling close(t) somewhere else that has access to t.

With Timers, you can still keep on using your julia instance for other purposes.

Upvotes: 3

Related Questions