How Meta Made Debugging Async Code Easier with Coroutines and Senders
… … Stack Traces for Async Code are Unhelpful Threadpool threads: #0 process_file(...) #5 pool.run() #10 __clone … … IO Thread: #0 async_read_some_at(...) #3 ctx Threadpool threads: #0 process_file(...) #5 pool.run() #10 … IO Thread: … #0 async_read_some_at(...) #3 ctx.run() #5 __clone … … Main thread: #0 unifex::sync_wait( … #0 async_read_some_at(...) … #12 unifex::sync_wait(...) #16 main() #19 __libc_start_main() … … Async Stacks are BetterStructured Concurrency Makes Async Stacks Possible0 码力 | 131 页 | 907.41 KB | 5 月前3Deciphering C++ Coroutines
Cheat Sheet - Awaitable 1 struct Awaitable { 2 bool await_ready (); 3 auto await_suspend (std:: coroutine_handle < promise_type >); 4 auto await_resume (); 5 };12/55 Cheat Sheet: Map of Coroutine Land13/55 Task18/55 Threads - A straightforward solution std::futurespawn_task () { return std:: async( outer_function ); }18/55 Threads - A straightforward solution main() spawn task()18/55 Threads auto data = co_await async_io (...); co_return IoResult :: from_io_data(data ); }24/55 Suspending nested coroutines Async inner_function () { auto data = co_await async_io (...); co_return 0 码力 | 156 页 | 1.79 MB | 5 月前3Coroutines and Structured Concurrency in Practice
demonstrated to justify switchingCallbacks vs coroutines // read length auto len = make_unique(); async_read(socket, buffer(len.get(), sizeof(int32_t)), [len = move(len)](auto ec, size_t len1){ && len1 == sizeof(int32_t)) { // read data auto buf = make_unique (*len); async_read(socket, buffer(buf.get(), *len), [buf = move(buf), len = *len] (auto // read length int32_t len; co_await async_read(s, buffer(&len, sizeof(len)), use_awaitable); // read data auto buf = make_unique (len); co_await async_read(s, buffer(buf.get(), len) 0 码力 | 103 页 | 1.98 MB | 5 月前3Falcon v3.0.0 Documentation
Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Summary Changes to Supported containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server in terms of resources and state # transitions, which map to HTTP verbs. class ThingsResource: async def on_get(self, req, resp): """Handles GET requests""" resp.status = falcon.HTTP_2000 码力 | 1055 页 | 739.30 KB | 1 年前3Falcon v3.0.1 Documentation
Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.1 Summary Fixed Contributors containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server in terms of resources and state # transitions, which map to HTTP verbs. class ThingsResource: async def on_get(self, req, resp): """Handles GET requests""" resp.status = falcon.HTTP_2000 码力 | 1058 页 | 741.59 KB | 1 年前3Falcon v3.0.0-b2 Documentation
HTTP error responses Full Unicode support Intuitive request and response objects Works great with async libraries like gevent Minimal attack surface for writing secure APIs 100% code coverage with a comprehensive Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Changes to Supported containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server0 码力 | 1041 页 | 730.21 KB | 1 年前3Falcon v3.0.0-b1 Documentation
HTTP error responses Full Unicode support Intuitive request and response objects Works great with async libraries like gevent Minimal attack surface for writing secure APIs 100% code coverage with a comprehensive Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Changes to Supported Falcon on it. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server0 码力 | 1028 页 | 725.86 KB | 1 年前3websockets Documentation Release 9.0
import asyncio import websockets async def hello(): uri = "ws://localhost:8765" async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") await websocket.recv() asyncio.get_event_loop() server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) start_server = websockets.serve(echo, "localhost" example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 81 页 | 352.88 KB | 1 年前3websockets Documentation Release 5.0
”: #!/usr/bin/env python import asyncio import websockets async def hello(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") asyncio.get_event_loop().run_until_complete( server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) asyncio.get_event_loop().run_until_complete( example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 56 页 | 245.43 KB | 1 年前3websockets Documentation Release 6.0
”: #!/usr/bin/env python import asyncio import websockets async def hello(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") asyncio.get_event_loop().run_until_complete( server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) asyncio.get_event_loop().run_until_complete( example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 58 页 | 253.08 KB | 1 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100