Parameters in context manager's __enter__ method?

skip at pobox.com skip at pobox.com
Wed Oct 24 10:06:56 EDT 2007


I am working on a file locking class which I'd like to work with Python
2.5's context managers.  The acquire method takes an optional timeout
argument:

    class FileLock:
        ...
        def acquire(self, timeout=None):
            ...

        def __enter__(self):
            self.acquire()
            return self

Can that optional timeout be somehow accommodated by the with statement?
(I'm thinking no, which may not be a big shortcoming anyway.)

Thx,

Skip





More information about the Python-list mailing list