Skip to content

Instantly share code, notes, and snippets.

@wd5gnr
Created October 25, 2023 19:44
Show Gist options
  • Save wd5gnr/0c48d5b8b2ba03055b6eabaee7c7f3ef to your computer and use it in GitHub Desktop.
Save wd5gnr/0c48d5b8b2ba03055b6eabaee7c7f3ef to your computer and use it in GitHub Desktop.
Sample Python asyncio Test
import asyncio
import testb
state={'done': 0 }
async def taskA():
global done
print("A")
await asyncio.sleep(5)
print("A'")
state['done']=1
def getDone():
return state['done']
async def amain():
print("amain")
asyncio.create_task(taskA())
asyncio.create_task(testb.taskB())
while True:
await asyncio.sleep(0)
def main():
asyncio.run(amain())
if __name__=="__main__":
main()
import asyncio
async def taskB():
import test
while True:
print(test.getDone())
await asyncio.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment