How to retry something with a timeout in Python?

tinnews at isbd.co.uk tinnews at isbd.co.uk
Tue Apr 28 16:56:13 EDT 2009


This feels like it should be simple but I can't see a clean way of
doing it at the moment.

I want to retry locking a file for a number of times and then give up,
in pseudo-code it would be something like:-


    for N times
        try to lock file
            if successful break out of for loop
    if we don't have a lock then give up and exit


How does one do this tidily in python?

-- 
Chris Green




More information about the Python-list mailing list