Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
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())

View file

@ -0,0 +1,10 @@
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win 32
Type "help", "copyright", "credits" or "license" for more information.
>>> from concurrent import futures
>>> with futures.ProcessPoolExecutor() as executor:
... _ = list(executor.map(print, 'Enjoy Rosetta Code'.split()))
...
Enjoy
Rosetta
Code
>>>

View file

@ -0,0 +1,9 @@
import threading
import random
def echo(text):
print(text)
threading.Timer(random.random(), echo, ("Enjoy",)).start()
threading.Timer(random.random(), echo, ("Rosetta",)).start()
threading.Timer(random.random(), echo, ("Code",)).start()

View file

@ -0,0 +1,8 @@
import threading
import random
def echo(text):
print(text)
for text in ["Enjoy", "Rosetta", "Code"]:
threading.Timer(random.random(), echo, (text,)).start()

View 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()

View file

@ -0,0 +1,9 @@
from __future__ import print_function
from multiprocessing import Pool
def main():
p = Pool()
p.map(print, 'Enjoy Rosetta Code'.split())
if __name__=="__main__":
main()

View file

@ -0,0 +1,9 @@
import random
from twisted.internet import reactor, task, defer
from twisted.python.util import println
delay = lambda: 1e-4*random.random()
d = defer.DeferredList([task.deferLater(reactor, delay(), println, line)
for line in 'Enjoy Rosetta Code'.split()])
d.addBoth(lambda _: reactor.stop())
reactor.run()

View file

@ -0,0 +1,7 @@
from __future__ import print_function
import random
import gevent
delay = lambda: 1e-4*random.random()
gevent.joinall([gevent.spawn_later(delay(), print, line)
for line in 'Enjoy Rosetta Code'.split()])