Skip to content

Commit 6ab6989

Browse files
committed
updates
1 parent 9605de0 commit 6ab6989

File tree

17 files changed

+388
-379
lines changed

17 files changed

+388
-379
lines changed

Examples/week-07-threading-and-multiprocessing/integrate/cheap-hack/integrate_main.py renamed to Examples/week-07-threading-and-multiprocessing/integrate/sequential/integrate_main.py

File renamed without changes.

Examples/week-07-threading-and-multiprocessing/race_condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def func():
1414
threads = []
1515
# with enough threads, there's sufficient overhead to cause a race
1616
# condition
17-
for i in xrange(10000):
17+
for i in xrange(20000):
1818
thread = threading.Thread(target=func)
1919
threads.append(thread)
2020
thread.start()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
from urllib.request import urlopen
6+
import asyncio
7+
8+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
9+
10+
# from decorators.decorators import timer
11+
12+
# @timer
13+
14+
results = asyncio.Queue()
15+
url = "http://localhost:37337"
16+
17+
@asyncio.coroutine
18+
def producer():
19+
conn = urlopen(url)
20+
result = conn.read()
21+
return result
22+
23+
@asyncio.coroutine
24+
def worker():
25+
result = yield from producer()
26+
results.put(result)
27+
28+
loop = asyncio.get_event_loop()
29+
30+
number_of_requests = 100
31+
32+
for i in range(number_of_requests):
33+
loop.run_until_complete(worker())
34+
35+
print( "made %d requests" % number_of_requests)

Examples/week-07-threading-and-multiprocessing/threading/integrate_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def threading_integrate(f, a, b, N, thread_count=2):
1515
"""break work into two chunks"""
1616
N_chunk = int(float(N) / thread_count)
1717
dx = float(b-a) / thread_count
18-
18+
1919
results = Queue.Queue()
2020

2121
def worker(*args):
2222
results.put(integrate(*args))
2323

2424
threads = []
2525
for i in xrange(thread_count):
26-
x0 = dx*i
26+
x0 = dx*i
2727
x1 = x0 + dx
2828
thread = threading.Thread(target=worker, args=(f, x0, x1, N_chunk))
2929
thread.start()

slides_sources/html_slides/07-profiling.html

Lines changed: 178 additions & 200 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)