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.
            Asked
            
        
        
            Active
            
        
            Viewed 2,207 times
        
    -1
            
            
        - 
                    use `time.sleep(s)` from `time` module. `import time; time.sleep(2)` – Nf4r Oct 14 '16 at 19:21
- 
                    1What'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
- 
                    1This 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 Answers
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
 
    