0

More out of curiosity, I was wondering how might I make a python script sleep for 1 second without using the time module?

Is there a computation that can be conducted in a while loop which takes a machine of n processing power a designated and indexable amount of time?

Adam.Er8
  • 12,675
  • 3
  • 26
  • 38
Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69
  • 6
    It's been a long time since you could get a reliable delay out of just trying to execute code that would take a certain time to complete. Computers don't work like that any more. – user2357112 Nov 18 '19 at 08:46
  • 3
    The processing time is depends on the machine you are working with and active processes on it. There is no fixed amount of time for an operation. – Guy Nov 18 '19 at 08:46
  • @Chris thanks for the helpful link – it does not, since I'm trying to explore a solution deliberately without the `time` module. – Yaakov Bressler Nov 18 '19 at 09:48

1 Answers1

1

As mentioned in comments for your second part of question:

The processing time is depends on the machine(computer and its configuration) you are working with and active processes on it. There isnt fixed amount of time for an operation.

It's been a long time since you could get a reliable delay out of just trying to execute code that would take a certain time to complete. Computers don't work like that any more.

But to answer your first question: you can use system calls and open a os process to sleep 1 second like:

import subprocess
subprocess.run(["sleep", "1"])
Community
  • 1
  • 1
erfan mehraban
  • 483
  • 3
  • 5
  • 13