Re: What does stats = await asyncio.to_thread(os.stat, url) do? (Was async I/O via threads is extremly slow)

"Peter J. Holzer" <[email protected]>
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
On 2025-06-24 00:32:26 +0200, Mild Shock wrote:
> So what does:
> 
> stats = await asyncio.to_thread(os.stat, url)
> 
> Whell it calls in a sparate new secondary thread:
> 
> os.stat(url)
> 
> It happends that url is only a file path, and
> the file path points to an existing file. So the
> secondary thread computs the stats, and terminates,

I think you are mostly measuring the time to create and destroy a thread
here, not anything about the performance of the asyncio framework.

        hjp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | [email protected]         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmhaabMACgkQ8g5IURL+
KF2Y1A/9G3oGKEHuw+TuE5gCD64VoKzddCy/s5vkEskCfq4sOnzUbHErs+3vFLKO
VQVx2p24qD2SlyErC0sypc03MQy/wRcP51OEzJvBlMHGq+ksasNGV7syhWwSV3WW
L6t11vza4P33+ZzogeUJpIHKNfkvUXLvaztgOUymYELfnKpZe/YR1vafeLMIawFx
v9grzZjaAzOeTjXh0sRvj20l9t/6Rri/83PiCH6fiuGQz1srTiFLLL2wxNfEM46h
LtPGmKbvVJsOwcmNht4b5nM/GA0/zWGBnkNOahvmd4T4ptoIJqxSe885DH9pkNA5
ubDy1kxB85nJoKWTGKy8Z7Y9LPsK6uyi+o+CLLN6jKjM6BVyaeQBBzjrRHsbIlaF
TvGuNujU6NmGEsSP7VcVmCvWU2ql47/M4dBF+xL2vp5baGUo5ROYDVlQyN5C21aU
WnvJpY57/tfJwtH18HhxMWpNYdZIchTO+0iTVcmWkTA82WIiC3o8k4WupIwhlzIU
eBhWp8IumPtIruUDVGTKCVmee5P8x3DLPHLNvkhGUPKGhwXKT1poFeK5PPGR80e4
eb4hBZmNYHkrXT/i2dipMS1XcE0CflUPPdfzpe7PpxQLeaZ6Zy4KMFs/EUh4Pzdq
FX0rdIOwhF/k0hUmBTvZCKCncATT4f3ixwGNwKlgol+ywS8BdFI=
=oLd0
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.