Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Concurrent-computing/Python/concurrent-computing-5.py
Normal file
14
Task/Concurrent-computing/Python/concurrent-computing-5.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import random, sys, time
|
||||
import threading
|
||||
|
||||
lock = threading.Lock()
|
||||
|
||||
def echo(s):
|
||||
time.sleep(1e-2*random.random())
|
||||
# use `.write()` with lock due to `print` prints empty lines occasionally
|
||||
with lock:
|
||||
sys.stdout.write(s)
|
||||
sys.stdout.write('\n')
|
||||
|
||||
for line in 'Enjoy Rosetta Code'.split():
|
||||
threading.Thread(target=echo, args=(line,)).start()
|
||||
Loading…
Add table
Add a link
Reference in a new issue