add all concurrence examples

This commit is contained in:
Mia von Steinkirch 2020-03-03 23:24:17 -08:00
parent 2333b724ec
commit 5224dc91ca
12 changed files with 49 additions and 2 deletions

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import random
import logging
import concurrent.futures

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import os
import time
import threading

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import os
import time
import threading

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import time
from gevent.pool import Pool
from gevent import monkey
@ -20,4 +22,3 @@ pool.join()
end_time = time.time()
print("Time for GreenSquirrel: %ssecs" % (end_time - start_time))
g

View file

@ -1,6 +1,8 @@
import multiprocessing
#!/usr/bin/env python3
import time
import random
import multiprocessing
def worker(n):

View file

@ -0,0 +1,10 @@
#!/usr/bin/env python3
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
p = Pool(5)
print(p.map(f, [1, 2, 3]))

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import threading
x = 0

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import threading
counter = 0

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import time
import random
import threading

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

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import time
from queue import Queue
from threading import Thread

View file

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import time
import threading