Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that you want a function in which you can have your program pause for exactly some amount of time. This sort of problem is solved by using a <code>Real Time Operating System</code> or <a href="http://en.wikipedia.org/wiki/Real-time_operating_system" rel="nofollow">RTOS</a>. Unfortunately, you are probably not using one of those. Assuming so, you have two options:</p> <ol> <li><a href="http://en.wikipedia.org/wiki/Busy_loop" rel="nofollow">Busy Loop</a></li> <li>Sleep</li> </ol> <p>A <code>Busy Loop</code> is what you are doing now. It has advantages and disadvantages. One advantage is that your process most likely remains active during a busy loop, meaning you are more likely to be accurate for small waiting periods. However, your operating system's scheduler can (and will) slice CPU time between your program and other programs that are running. You will only be accurate if your program has the CPU when your wait time is over. The primary disadvantage of a busy loop is that you are constantly using the CPU while you are waiting--that's the 'busy' part. This means that other programs running at the same time won't always get use of the CPU if your program is waiting.</p> <p>A <code>Sleep</code> call is a simple function provided by python's libraries. <code>time.sleep(seconds)</code> will cause your program to be taken off the CPU and the operating system won't wake it back up until the time has passed. The advantage here is that you are not needlessly using the CPU while you wait. The disadvantage is that your program will not be active until the operating system reactivates it and therefore the time may not be accurate.</p> <p>If you use sleep, you could also use something like <a href="http://en.wikipedia.org/wiki/Nice_%28Unix%29" rel="nofollow">Nice</a> to give your process more priority to the scheduler and therefore more CPU-time. Using a very high priority for your process would make sleep timings more accurate. This, of course, comes with the cost of possibly starving other processes from using the CPU.</p> <p>Personally, I would recommend using sleep, but your mileage may vary. The bottom line is that there is nothing that python can do to give you an accurate waiting time. You need a real-time operating system for that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload