# Input from System Clock

**URL:** <https://discourse.julialang.org/t/input-from-system-clock/45898>\
**Category:** Internals & Design\
**Created:** [September 1, 2020, 2:25pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898 "2020-09-01T14:25:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![onButtonUp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onbuttonup/32/3098_2.png) [@onButtonUp](https://discourse.julialang.org/u/onButtonUp)\
**Post date:** [September 1, 2020, 2:25pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898/1 "2020-09-01T14:25:32Z")

</div>

Not sure if I am approaching a project from the wrong direction, but I wonder how the system clock may be used as an input to a Julia program. Say, every 50mS I want a signal (like an interrupt) to start a process. I don’t want the program to check all the time to see if 50mS has passed (because then the program spends a lot of time just checking the time). I would like the program to not do anything until the system clock triggers (or sends an interrupt signal) to the program. I am not sure if I can do that within a Julia program, or if I should approach this from the system side (have the system call the program every 50mS . . .)

More generally, does Julia have access to any of the system interrupts ?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [September 1, 2020, 2:38pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898/2 "2020-09-01T14:38:25Z")

</div>

You could simply use a loop and call `sleep(0.05)` inside it.

---

<div class="post-metadata">

**Author:** ![onButtonUp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/onbuttonup/32/3098_2.png) [@onButtonUp](https://discourse.julialang.org/u/onButtonUp)\
**Post date:** [September 1, 2020, 2:45pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898/3 "2020-09-01T14:45:51Z")

</div>

: ) okay, sleep may work. I would like to know, then, how sleep actually works. I can test it (. . . later). When it sleeps it releases CPU resources . . . what is the mechanism that wakes it up?

* * *

Maybe what I am thinking is a Julia program that runs in the background (and consumes little CPU resources) until a timer calls it to wake up and run.

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [September 1, 2020, 4:30pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898/4 "2020-09-01T16:30:57Z")

</div>

Create a [`Timer`](https://docs.julialang.org/en/v1/base/base/#Base.Timer) and `wait` for it in a `Task`. You then can let the task call a function at each tick.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 1, 2020, 6:01pm UTC](https://discourse.julialang.org/t/input-from-system-clock/45898/5 "2020-09-01T18:01:13Z")

</div>

> [@onButtonUp](#):
>
> I would like to know, then, how sleep actually works.

A great way to figure this out is using the `@edit` macro, e.g. `@edit sleep(0.05)` in the REPL should point you to the implementation. In the case of `sleep` it’s just calling `wait(Timer(0.05))`, as @pbayer already pointed out.
