# About the time.sleep

**URL:** <https://discourse.slicer.org/t/about-the-time-sleep/10171>\
**Category:** Development\
**Created:** [February 9, 2020, 12:02pm UTC](https://discourse.slicer.org/t/about-the-time-sleep/10171 "2020-02-09T12:02:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [February 9, 2020, 12:02pm UTC](https://discourse.slicer.org/t/about-the-time-sleep/10171/1 "2020-02-09T12:02:23Z")

</div>

```
for _ in range(20):
	n += 1
	print('n')
	time.sleep(1)

```

The printing results seems to be printed in the last time… Can I replace the time.sleep in slicer for waiting time?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 9, 2020, 4:32pm UTC](https://discourse.slicer.org/t/about-the-time-sleep/10171/2 "2020-02-09T16:32:59Z")

</div>

Hi @timeanddoctor -

The native python `time` package is not integrated with the Slicer application event loop, managed by Qt. So you need to use [`QTimer`](https://doc.qt.io/qt-5/qtimer.html) methods instead.

Something like this:

```auto
for i in range(5):
   qt.QTimer.singleShot(1000*i, lambda i=i: print(i))

```

The other advantage is that the application will remain responsive while waiting for the time to elapse. Of course working asynchronously with the event loop is different from conventional sequential programming models, but it’s central to how the application works.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 10, 2020, 12:55am UTC](https://discourse.slicer.org/t/about-the-time-sleep/10171/3 "2020-02-10T00:55:03Z")

</div>

If you must stay in a processing loop and still want to update the GUI then you can call `slicer.app.processEvents()`:

```python
for n in range(20):
    print(n)
    time.sleep(1)
    slicer.app.processEvents() # update GUI

```
