Title: Why using synchronous get in flags_asyncio.py · Issue #40 · fluentpython/example-code-2e · GitHub
Open Graph Title: Why using synchronous get in flags_asyncio.py · Issue #40 · fluentpython/example-code-2e
X Title: Why using synchronous get in flags_asyncio.py · Issue #40 · fluentpython/example-code-2e
Description: When downloading the flags in async def get_flag(client: AsyncClient, cc: str) -> bytes: 4 url = f'{BASE_URL}/{cc}/{cc}.gif'.lower() resp = await client.get(url, timeout=6.1, follow_redirects=True) 5 return resp.read() 6 it seems that we...
Open Graph Description: When downloading the flags in async def get_flag(client: AsyncClient, cc: str) -> bytes: 4 url = f'{BASE_URL}/{cc}/{cc}.gif'.lower() resp = await client.get(url, timeout=6.1, follow_redirects=True)...
X Description: When downloading the flags in async def get_flag(client: AsyncClient, cc: str) -> bytes: 4 url = f'{BASE_URL}/{cc}/{cc}.gif'.lower() resp = await client.get(url, timeout=6.1, follow_redi...
Opengraph URL: https://github.com/fluentpython/example-code-2e/issues/40
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Why using synchronous get in flags_asyncio.py","articleBody":"When downloading the flags in \r\n```\r\nasync def get_flag(client: AsyncClient, cc: str) -\u003e bytes: 4\r\n url = f'{BASE_URL}/{cc}/{cc}.gif'.lower()\r\n resp = await client.get(url, timeout=6.1,\r\n follow_redirects=True) 5\r\n return resp.read() 6\r\n```\r\nit seems that we read the response using .read() which is synchronous, why don't we \r\n```\r\nreturn await resp.aread()\r\n```\r\ninstead? \r\n\r\nThe explanation seems to be for client.get() where it is doing network IO asynchrnously provided by httpx. But not for read()\r\n```\r\n6\r\n\r\n Network I/O operations are implemented as coroutine methods, so they are driven asynchronously by the asyncio event loop.\r\n```","author":{"url":"https://github.com/ngokchaoho","@type":"Person","name":"ngokchaoho"},"datePublished":"2023-12-13T06:54:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/40/example-code-2e/issues/40"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:32759f38-d6ed-5b4d-cbb0-4f7df4cfd31b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3A0:2DDF76:1B9E38:2542EC:69714FEA |
| html-safe-nonce | 908c74bfaa7d54079fdd4e7eeec571fb19f220504cbba2d2cebe74c8b942f302 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0EwOjJEREY3NjoxQjlFMzg6MjU0MkVDOjY5NzE0RkVBIiwidmlzaXRvcl9pZCI6IjQyODkyMzkyNjczOTAwODMwNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2722c94d0c419c53b80331bcda9f860db5355f7a164f2ae4a0350cfadac84a2a |
| hovercard-subject-tag | issue:2039071838 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fluentpython/example-code-2e/40/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b66b9349445db1fa100e1f5d44790cbb56c44540383b7fcf1f62e627748d8e91/fluentpython/example-code-2e/issues/40 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b66b9349445db1fa100e1f5d44790cbb56c44540383b7fcf1f62e627748d8e91/fluentpython/example-code-2e/issues/40 |
| og:image:alt | When downloading the flags in async def get_flag(client: AsyncClient, cc: str) -> bytes: 4 url = f'{BASE_URL}/{cc}/{cc}.gif'.lower() resp = await client.get(url, timeout=6.1, follow_redirects=True)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ngokchaoho |
| hostname | github.com |
| expected-hostname | github.com |
| None | da7cbccf7f40bcd9540003423d9bef63b2fe7bb0b73fc59d91b5ae5b46000c90 |
| turbo-cache-control | no-preview |
| go-import | github.com/fluentpython/example-code-2e git https://github.com/fluentpython/example-code-2e.git |
| octolytics-dimension-user_id | 9216311 |
| octolytics-dimension-user_login | fluentpython |
| octolytics-dimension-repository_id | 176997413 |
| octolytics-dimension-repository_nwo | fluentpython/example-code-2e |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 176997413 |
| octolytics-dimension-repository_network_root_nwo | fluentpython/example-code-2e |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c9e6c71b091ca750658a3b2e3c82b0b85555f788 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width