mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 22:20:22 -04:00
post done
This commit is contained in:
parent
be98abd3b5
commit
f47aaa5195
3 changed files with 17 additions and 2 deletions
15
Concurrence_examples/asyncio_simple_example.py
Normal file
15
Concurrence_examples/asyncio_simple_example.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
async def delayed_hello():
|
||||||
|
print("Hello ")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
print("World!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.run_until_complete(delayed_hello())
|
||||||
|
loop.close()
|
|
@ -9,9 +9,9 @@ def return_after_5_secs(message):
|
||||||
return message
|
return message
|
||||||
|
|
||||||
pool = ThreadPoolExecutor(3)
|
pool = ThreadPoolExecutor(3)
|
||||||
|
|
||||||
|
|
||||||
future = pool.submit(return_after_5_secs, ("hello"))
|
future = pool.submit(return_after_5_secs, ("hello"))
|
||||||
|
|
||||||
print(future.done())
|
print(future.done())
|
||||||
sleep(5)
|
sleep(5)
|
||||||
print(future.done())
|
print(future.done())
|
||||||
|
|
|
@ -33,4 +33,4 @@ task_queue.join()
|
||||||
|
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
|
|
||||||
print("Time: %ssecs" % (end_time - start_time))
|
print('Time: {} secs'.format(end_time - start_time))
|
Loading…
Add table
Add a link
Reference in a new issue