tinytag icon indicating copy to clipboard operation
tinytag copied to clipboard

asyncio interfaces

Open aw-was-here opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. tinytag is part of a larger app that needs to handle events as they arise. It would be useful if there was an asyncio interface to share CPU time.

Describe the solution you'd like File reads for large files to use aiofiles or equivalent so that they aren't fully blocking reads.

Describe alternatives you've considered Pushing the tinytag.get() call into an asyncio thread executor... which would work, but this feature feels like something that tinytag should support natively.

aw-was-here avatar May 13 '23 05:05 aw-was-here

Would this change be enough? https://github.com/devsnd/tinytag/pull/178

mathiascode avatar Jun 02 '23 20:06 mathiascode

Without an await somewhere, it is still holding the execution lock.

aw-was-here avatar Jun 02 '23 23:06 aw-was-here

I assume you could do something like

async with aiofiles.open('filename', mode='rb') as f:
    contents = await f.read()
    tag = TinyTag.get(file_obj=BytesIO(contents))

If this isn't enough, suggestions on how to accomplish what you need without adding asyncio and aiofiles as dependencies to tinytag would be welcome.

mathiascode avatar Jun 02 '23 23:06 mathiascode