21

In Matlab, the function

pause(x)

Stops execution for x seconds. Is there something similar in Julia?

3
  • 3
    sleep(seconds) Block the current task for a specified number of seconds. The minimum sleep time is 1 millisecond or input of 0.001. Commented Jun 24, 2015 at 18:25
  • 1
    Thanks @brauner, sleep does the job. Please post it below so I can accept. Commented Jun 24, 2015 at 18:34
  • of course. Happy to do so. :) Commented Jun 24, 2015 at 18:40

2 Answers 2

28

One method in julia is to use the sleep() function which takes the number of seconds as a parameter. The minimum number of time is 1 millisecond or an input of 0.001.

Sign up to request clarification or add additional context in comments.

Comments

0

Not a serious answer, but I have a note-to-self from julia v0.4 days to use the following to pause execution for t seconds:

f = t -> watch_file(".",t)

Here's the current stable version documentation of watch_file.

I have another similar note suggesting this:

f = t -> (b=time(); while b+t > time() end)

I have no earthly idea why either would be preferred method of pausing program execution vs. sleep(x), perhaps someone could comment.

2 Comments

I compared accuracy for sleep() and FileWatching.watch_file() based f and it's comparable.
It seems that sleep is non-blocking. So that if you @spawn a function that calls sleep, it will allow other tasks to run once it starts to sleep. your 2nd note will not do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.