mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-18 06:30:23 -04:00
add all concurrence examples
This commit is contained in:
parent
2333b724ec
commit
5224dc91ca
12 changed files with 49 additions and 2 deletions
18
Concurrence_examples/threadpool_example.py
Normal file
18
Concurrence_examples/threadpool_example.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from time import sleep
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
|
||||
def return_after_5_secs(message):
|
||||
sleep(5)
|
||||
return message
|
||||
|
||||
pool = ThreadPoolExecutor(3)
|
||||
|
||||
|
||||
future = pool.submit(return_after_5_secs, ("hello"))
|
||||
print(future.done())
|
||||
sleep(5)
|
||||
print(future.done())
|
||||
print(future.result())
|
Loading…
Add table
Add a link
Reference in a new issue