Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used on local apps? #30

Closed
Tosh0kan opened this issue Jun 12, 2024 · 6 comments
Closed

Can this be used on local apps? #30

Tosh0kan opened this issue Jun 12, 2024 · 6 comments

Comments

@Tosh0kan
Copy link

Tosh0kan commented Jun 12, 2024

By local apps, I mean asynchronous tasks where the I/O bottleneck is local (eg reading/saving from/to disk)? For example, I created a program that converts image formats, and the relevant part is shown below:

dir_ls = os.listdir(path_outer)
file_list = [path_outer + '\\' + e for e in dir_ls]

try:
    os.mkdir(path_outer + '\\' + 'converted')
except FileExistsError:
    pass
await asyncio.gather(*(asyncio.to_thread(file_convert, e, fmt, batch=True, count=i) for i, e in enumerate(file_list, start=1)))

Does Winloop has something akin to the .to_thread() method or is this exclusively meant to be used for web projects?

@Vizonex
Copy link
Owner

Vizonex commented Jun 15, 2024 via email

@Tosh0kan
Copy link
Author

Both with regular asyncio and with aiofiles, how would winloop be implemented in the logic?

@Vizonex
Copy link
Owner

Vizonex commented Jun 15, 2024 via email

@Tosh0kan
Copy link
Author

Tosh0kan commented Jun 15, 2024

Like, just add winloop.install() before the asyncio.run() like this?

winloop.install()
asyncio.run(img_convert(args.path, args.format, args.boost))

If so, I'm not noticing any real improvement on average, around a second or so. I'm just wondering if I'm doing this correctly.

@Vizonex
Copy link
Owner

Vizonex commented Jun 21, 2024 via email

@Tosh0kan
Copy link
Author

I see. Thank you for all the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants