GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — use asyncio.sleep() coroutine correctly (#41) · NoneGG/aredis@b080769

This repository was archived by the owner on Oct 29, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • examples
    • sanic_server.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎examples/sanic_server.py‎

Copy file name to clipboardExpand all lines: examples/sanic_server.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ async def _stream(res):
1515
redis = aredis.StrictRedis()
1616
pub = redis.pubsub()
1717
await pub.subscribe('test')
18-
while True:
18+
end_time = app.loop.time() + 30
19+
while app.loop.time() < end_time:
1920
await redis.publish('test', 111)
20-
message = await pub.get_message()
21-
if message:
22-
res.write(message)
23-
asyncio.sleep(5)
21+
message = None
22+
while not message:
23+
message = await pub.get_message()
24+
res.write(message)
25+
await asyncio.sleep(0.1)
2426
return stream(_stream)
2527

2628
if __name__ == "__main__":
27-
app.run(host="0.0.0.0", port=8000)
29+
app.run(host="0.0.0.0", port=8000)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.