Skip to content

Instantly share code, notes, and snippets.

View apoorv007's full-sized avatar

Apoorv Garg apoorv007

  • Archsaber
  • India
View GitHub Profile
@apoorv007
apoorv007 / coroutine_example.py
Last active June 24, 2018 20:05
Python coroutine example
import asyncio
# definition of a coroutine
async def coroutine_1():
print('coroutine_1 is active on the event loop')
print('coroutine_1 yielding control. Going to be blocked for 4 seconds')
await asyncio.sleep(4)
print('coroutine_1 resumed. coroutine_1 exiting')
@apoorv007
apoorv007 / asyncio_example.py
Last active April 26, 2020 20:54
Aynchronous programming with asyncio
import asyncio
# this is a coroutine definition
async def fake_network_request(request):
print('making network call for request: ' + request)
# simulate network delay
await asyncio.sleep(1)
return 'got network response for request: ' + request