kopia lustrzana https://github.com/micropython/micropython-lib
asyncio: Add basic asyncio stream interface test.
rodzic
916eb33727
commit
18c0b2c2f0
|
@ -0,0 +1,25 @@
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def print_http_headers(url):
|
||||||
|
reader, writer = yield from asyncio.open_connection(url, 80)
|
||||||
|
print(reader, writer)
|
||||||
|
print("================")
|
||||||
|
query = "GET / HTTP/1.0\n\n"
|
||||||
|
print(query.encode('latin-1'))
|
||||||
|
yield from writer.write(query)
|
||||||
|
while True:
|
||||||
|
line = yield from reader.readline()
|
||||||
|
# 1/0
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
if line:
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
url = "google.com"
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
#task = asyncio.async(print_http_headers(url))
|
||||||
|
#loop.run_until_complete(task)
|
||||||
|
loop.call_soon(print_http_headers(url))
|
||||||
|
loop.run_forever()
|
||||||
|
loop.close()
|
Ładowanie…
Reference in New Issue