forked from LBRYCommunity/lbry-sdk
Support official contextlib.aclosing() when it's available.
This commit is contained in:
parent
fe07aac79c
commit
fad84c771c
1 changed files with 10 additions and 6 deletions
|
@ -130,12 +130,16 @@ def get_sd_hash(stream_info):
|
||||||
def json_dumps_pretty(obj, **kwargs):
|
def json_dumps_pretty(obj, **kwargs):
|
||||||
return json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': '), **kwargs)
|
return json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': '), **kwargs)
|
||||||
|
|
||||||
@contextlib.asynccontextmanager
|
try:
|
||||||
async def aclosing(thing):
|
# the standard contextlib.aclosing() is available in 3.10+
|
||||||
try:
|
from contextlib import aclosing
|
||||||
yield thing
|
except ImportError:
|
||||||
finally:
|
@contextlib.asynccontextmanager
|
||||||
await thing.aclose()
|
async def aclosing(thing):
|
||||||
|
try:
|
||||||
|
yield thing
|
||||||
|
finally:
|
||||||
|
await thing.aclose()
|
||||||
|
|
||||||
def async_timed_cache(duration: int):
|
def async_timed_cache(duration: int):
|
||||||
def wrapper(func):
|
def wrapper(func):
|
||||||
|
|
Loading…
Reference in a new issue