Anonymous user
Concurrent computing: Difference between revisions
Updated whitespace, removed versions for old code, and removed code using external libraries as standard libraries allows execution of code. It's suspicious that three standard libraries do the job, so either the task or the code isn't precise enough.
m (Removed output as specified in task and updated whitespace.) |
(Updated whitespace, removed versions for old code, and removed code using external libraries as standard libraries allows execution of code. It's suspicious that three standard libraries do the job, so either the task or the code isn't precise enough.) |
||
Line 1,583:
=={{header|Python}}==
<lang python>import asyncio
async def print_(string: str) -> None:
print(string)
async def main():
strings = ['Enjoy', 'Rosetta', 'Code']
coroutines = map(print_, strings)
await asyncio.gather(*coroutines)
if __name__ == '__main__':
asyncio.run(main())</lang>
=== threading.Thread ===
<lang python>import random, sys, time
import threading
lock = threading.Lock()
def echo(s):
time.sleep(1e-2*random.random())
Line 1,650 ⟶ 1,602:
sys.stdout.write(s)
sys.stdout.write('\n')
for line in 'Enjoy Rosetta Code'.split():
threading.Thread(target=echo, args=(line,)).start()</lang>
=== multiprocessing ===
<lang python>from __future__ import print_function
from multiprocessing import Pool
def main():
p = Pool()
p.map(print, 'Enjoy Rosetta Code'.split())
if __name__=="__main__":
main()</lang>
=={{header|Racket}}==
|