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 — python_test/test56.py at master · sinferwu/python_test

Expand file tree

/

test56.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
38 lines (27 loc) · 1.06 KB
/

test56.py

Copy path

File metadata and controls

38 lines (27 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr.bin.env python 3
# -*- coding: utf-8 -*-
'''
练习python的aiohttp
练习服务器上的异步操作
'''
__author__ = 'sergiojune'
import asyncio
from aiohttp import web
async def index(request): # 首页返回一个h1标签
await asyncio.sleep(0.5)
return web.Response(body=b'<h1>index</h1>', content_type='text/html')
async def hello(request): # 根据url参数返回信息
await asyncio.sleep(0.5)
return web.Response(body=b'<h1>hello %s</h1>' % request.match_info['name'], content_type='text/html')
# 初始化服务器,也是一个coroutine
async def init(loop): # 接受协程池
app = web.Application(loop=loop)
# 添加反应路径
app.router.add_route('GET', '/', index)
app.router.add_route('GET', '/hello/{name}', hello)
s = loop.create_server(app.make_handler(), '', 80) # 用loop.create_server创建tcp协议
print('sever is start in 127.0.0.1:80')
return s
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever() # 服务器永远运行
You are visitor 01402520 — 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.