@@ -258,7 +258,9 @@ executor when the task is computationally expensive.
258258There are two main ways of executing things in parallel using the two
259259Executors. One way is with the `map(func, iterables) ` method. This works
260260almost exactly like the builtin `map() ` function, except it will execute
261- everything in parallel. ::
261+ everything in parallel. :
262+
263+ .. code-block :: python
262264
263265 from concurrent.futures import ThreadPoolExecutor
264266 import requests
@@ -301,7 +303,8 @@ add_done_callback(fn)
301303 Attach a callback function that will be executed (as `fn(future) `) when the
302304 scheduled callable returns.
303305
304- ::
306+
307+ .. code-block :: python
305308
306309 from concurrent.futures import ProcessPoolExecutor, as_completed
307310
@@ -355,7 +358,9 @@ The standard library comes with a `threading`_ module that allows a user to
355358work with multiple threads manually.
356359
357360Running a function in another thread is as simple as passing a callable and
358- it's arguments to `Thread `'s constructor and then calling `start() `::
361+ it's arguments to `Thread `'s constructor and then calling `start() `:
362+
363+ .. code-block :: python
359364
360365 from threading import Thread
361366 import requests
@@ -367,12 +372,16 @@ it's arguments to `Thread`'s constructor and then calling `start()`::
367372 some_thread = Thread(get_webpage, ' http://google.com/' )
368373 some_thread.start()
369374
370- To wait until the thread has terminated, call `join() `::
375+ To wait until the thread has terminated, call `join() `:
376+
377+ .. code-block :: python
371378
372379 some_thread.join()
373380
374381 After calling `join() `, it is always a good idea to check whether the thread is
375- still alive (because the join call timed out)::
382+ still alive (because the join call timed out):
383+
384+ .. code-block :: python
376385
377386 if some_thread.is_alive():
378387 print (" join() must have timed out." )
@@ -389,7 +398,10 @@ which are difficult to debug. A good example is this `stackoverflow post`_.
389398The way this can be avoided is by using a `Lock `_ that each thread needs to
390399acquire before writing to a shared resource. Locks can be acquired and released
391400through either the contextmanager protocol (`with ` statement), or by using
392- `acquire() ` and `release() ` directly. Here is a (rather contrived) example::
401+ `acquire() ` and `release() ` directly. Here is a (rather contrived) example:
402+
403+
404+ .. code-block :: python
393405
394406 from threading import Lock, Thread
395407
@@ -402,7 +414,8 @@ through either the contextmanager protocol (`with` statement), or by using
402414
403415 def monitor_website (some_website ):
404416 """
405- Monitor a website and then if there are any changes, log them to disk.
417+ Monitor a website and then if there are any changes,
418+ log them to disk.
406419 """
407420 while True :
408421 changes = check_for_changes(some_website)
0 commit comments