Created
October 25, 2023 19:44
-
-
Save wd5gnr/0c48d5b8b2ba03055b6eabaee7c7f3ef to your computer and use it in GitHub Desktop.
Sample Python asyncio Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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