-1

I'm calling a method which run time is undefiniable. I want to wait for it some second (for example 2 sec) and after then I want to step my program next.

Kroy
  • 299
  • 1
  • 5
  • 18
  • use `time.sleep(s)` from `time` module. `import time; time.sleep(2)` – Nf4r Oct 14 '16 at 19:21
  • 1
    What's the method? Maybe `time.sleep` is a valid solution, but it could cause race conditions. – Rafael Barros Oct 14 '16 at 19:22
  • You need to do a basic Google search before asking a question: https://docs.python.org/3/library/time.html – Frogboxe Oct 14 '16 at 19:22
  • 1
    This is actually a much more complicated question than everyone is treating it. What you want to do is use `multiprocessing` or `threading` to start a child thread that executes the method. You then want the parent to kill the child if it hasn't returned a value after the allotted time. This is not easy stuff. Why don't you do some reading on those two modules and come back when you have more concrete questions. – Patrick Haugh Oct 14 '16 at 19:27

2 Answers2

4

I think this is a more suitable answer to the question: break the function after certain time

P.S: Could not post it as a comment due to insufficient reputation.

Community
  • 1
  • 1
Vikas Tikoo
  • 1,545
  • 11
  • 14
0

I believe you are looking for the sleep function in the time module.

https://docs.python.org/2/library/time.html#time.sleep

Jay
  • 11
  • 1