BruceEckel / Python 3 Patterns & Idioms (http://mindviewinc.com/Books/Python3Patterns/Index.php)
An open source book written and edited by Bruce Eckel with contributions and help from the Python community. Published under the Creative Commons Attribution-Share Alike 3.0 license. To download the current version of the HTML book and example code, click the "download" link you'll see in the upper right. This includes the sources for building the book.
$ hg clone http://bitbucket.org/BruceEckel/python-3-patterns-idioms/
| commit 58: | bf9f2400baf7 |
| parent 57: | 6b67f5810db4 |
| branch: | default |
12 months ago
Changed (Δ1.7 KB):
src/CoroutinesAndConcurrency.rst (41 lines added, 2 lines removed)
src/PythonDecorators.rst (4 lines added, 1 lines removed)
src/PythonForProgrammers.rst (6 lines added, 0 lines removed)
Up to file-list src/CoroutinesAndConcurrency.rst:
7 |
7 |
GIL: Global Interpreter Lock |
8 |
8 |
|
9 |
9 |
******************************************************************************** |
10 |
Coroutines |
|
10 |
Coroutines, Concurrency & Distributed Systems |
|
11 |
11 |
******************************************************************************** |
12 |
12 |
|
13 |
13 |
Primary focus should be on: |
| … | … | @@ -20,6 +20,40 @@ and then showing some alternative techni |
20 |
20 |
|
21 |
21 |
foo bar :func:`input` baz. |
22 |
22 |
|
23 |
Multiprocessing |
|
24 |
=============================================================================== |
|
25 |
||
26 |
Example by Michele Simionato in comp lang python. |
|
27 |
Here is an example of using multiprocessing (which is included |
|
28 |
in Python 2.6 and easy_installable in older Python versions) |
|
29 |
to print a spin bar while a computation is running:: |
|
30 |
||
31 |
import sys, time |
|
32 |
import multiprocessing |
|
33 |
DELAY = 0.1 |
|
34 |
DISPLAY = [ '|', '/', '-', '\\' ] |
|
35 |
def spinner_func(before='', after=''): |
|
36 |
write, flush = sys.stdout.write, sys.stdout.flush |
|
37 |
pos = -1 |
|
38 |
while True: |
|
39 |
pos = (pos + 1) % len(DISPLAY) |
|
40 |
msg = before + DISPLAY[pos] + after |
|
41 |
write(msg); flush() |
|
42 |
write('\x08' * len(msg)) |
|
43 |
time.sleep(DELAY) |
|
44 |
def long_computation(): |
|
45 |
# emulate a long computation |
|
46 |
time.sleep(3) |
|
47 |
if __name__ == '__main__': |
|
48 |
spinner = multiprocessing.Process( |
|
49 |
None, spinner_func, args=('Please wait ... ', '')) |
|
50 |
spinner.start() |
|
51 |
try: |
|
52 |
long_computation() |
|
53 |
print 'Computation done' |
|
54 |
finally: |
|
55 |
spinner.terminate() |
|
56 |
||
23 |
57 |
Further Reading |
24 |
58 |
================================================================================ |
25 |
59 |
|
| … | … | @@ -30,4 +64,9 @@ Further Reading |
30 |
64 |
that functional languages don't help that much with this problem. |
31 |
65 |
|
32 |
66 |
http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/ |
33 |
||
67 |
||
68 |
.. Good introduction to Twisted: |
|
69 |
.. http://jessenoller.com/2009/02/11/twisted-hello-asynchronous-programming/ |
|
70 |
||
71 |
.. Also |
|
72 |
.. http://jessenoller.com/2009/02/02/an-interview-with-adam-olsen-author-of-safe-threading-completely-different/ |
Up to file-list src/PythonDecorators.rst:
| … | … | @@ -486,7 +486,7 @@ Further Reading |
486 |
486 |
http://www.siafoo.net/article/68 |
487 |
487 |
|
488 |
488 |
http://www.ddj.com/web-development/184406073 |
489 |
Philip Eby introduces decorators. |
|
489 |
Philip Eby introduces decorators. |
|
490 |
490 |
|
491 |
491 |
http://www.informit.com/articles/article.aspx?p=1309289&seqNum=4 |
492 |
492 |
Class Decorators. |
| … | … | @@ -505,3 +505,6 @@ Further Reading |
505 |
505 |
Class decorators |
506 |
506 |
|
507 |
507 |
.. Examples http://www.python.org/dev/peps/pep-0318/#examples |
508 |
||
509 |
.. Peek inside a decorated function: |
|
510 |
.. http://groups.google.com/group/comp.lang.python/browse_thread/thread/0fb2ee45dbc101b1 |
Up to file-list src/PythonForProgrammers.rst:
| … | … | @@ -443,9 +443,15 @@ Further Reading |
443 |
443 |
Building a Virtual Environment for Running Python 3: |
444 |
444 |
http://pypi.python.org/pypi/virtualenv |
445 |
445 |
|
446 |
Excellent Newsfeed Following Python Articles from Everywhere: |
|
447 |
http://www.planetpython.org/ |
|
448 |
||
446 |
449 |
|
447 |
450 |
.. Good description of the Python packaging system: |
448 |
451 |
.. http://nameless-sorrows.blogspot.com/2009/02/custom-namespacing-system-for-python.html |
449 |
452 |
|
450 |
453 |
.. Getters and setters in Python: |
451 |
454 |
.. http://eli.thegreenplace.net/2009/02/06/getters-and-setters-in-python/ |
455 |
||
456 |
.. The 'with' statement (might require a separate chapter?): |
|
457 |
.. http://jessenoller.com/2009/02/03/get-with-the-program-as-contextmanager-completely-different/ |
