trbs / pid

Pidfile featuring stale detection and file-locking, can also be used as context-manager or decorator
https://pypi.python.org/pypi/pid/
Apache License 2.0
102 stars 26 forks source link

Support contextlib.ContextDecorator? #29

Closed spumer closed 4 years ago

spumer commented 4 years ago

ContextDecorator allow use the same object as decorator and context manager.

It's very simple and more pythonic than additional decorator. But ContextDecorator added only in 3.2 in standart library.

What do you think about that?

trbs commented 4 years ago

Think we should be able to do this seamlessly ?

Something like:

try:
    from contextdecorator import ContextDecorator as BaseObject
except ImportError:
    BaseObject = object

class PidFile(BaseObject):
    ...

If so seems like a good addition to me :-)

spumer commented 4 years ago

Yea, i think yes. I will make a PR :)

trbs commented 4 years ago

See https://github.com/trbs/pid/commit/afff6e9d3b052f22fd25546db9bd99b55daedb9c and https://pypi.org/project/pid/3.0.2/

Thanks for the suggestion !