Closed Tosh0kan closed 3 months ago
On Tue, Jun 11, 2024 at 8:02 PM Tosh0kan @.***> wrote:
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: passawait 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?
— Reply to this email directly, view it on GitHub https://github.com/Vizonex/Winloop/issues/30, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3K7GGRKTBKP2BOMDM4HQWDZG6M35AVCNFSM6AAAAABJFLCIG2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DONJVGM3DKNA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
You should be able to use .to_thread but I highly recommend you try something like aiofiles or some asynchronous os library with winloop but winloop isn’t just made for severs. You can use it for anything. The biggest benchmark though is networking but that doesn’t mean there isn’t a performance increase.
Both with regular asyncio and with aiofiles, how would winloop be implemented in the logic?
On Sat, Jun 15, 2024 at 9:36 AM Tosh0kan @.***> wrote:
Both with regular asyncio and with aiofiles, how would winloop be implemented in the logic?
— Reply to this email directly, view it on GitHub https://github.com/Vizonex/Winloop/issues/30#issuecomment-2169799353, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3K7GGXPGS5DX3NOB52T6B3ZHRGNNAVCNFSM6AAAAABJFLCIG2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZG44TSMZVGM . You are receiving this because you commented.Message ID: @.***>
Simply calling install() or run() will replace the internal loop for winloop’s loop.
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.
On Sat, Jun 15, 2024 at 10:21 AM Tosh0kan @.***> wrote:
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. I'm just wondering if I'm doing this correctly.
— Reply to this email directly, view it on GitHub https://github.com/Vizonex/Winloop/issues/30#issuecomment-2169888807, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3K7GGT77IR3NMQACSB7PCDZHRLZNAVCNFSM6AAAAABJFLCIG2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZHA4DQOBQG4 . You are receiving this because you commented.Message ID: @.***>
Yes, otherwise use
winloop.run()
I see. Thank you for all the help!
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:
Does Winloop has something akin to the
.to_thread()
method or is this exclusively meant to be used for web projects?