Skip to content

Commit

Permalink
Docs: Wrap lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan A. Jones authored and jawajack committed Sep 9, 2015
1 parent a43c0eb commit 2dcb8d5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tutorial/threading_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#
# Library imports
# ===============
# Read the `threading docs <https://docs.python.org/2/library/threading.html#thread-objects>`_
# carefully to understand this program's operation.
from threading import Thread, Lock
from time import sleep
#
Expand Down Expand Up @@ -39,12 +41,18 @@ def __init__(self,
# Any extra args.
**kwargs):

# Thread.__init__ `must <https://docs.python.org/2/library/threading.html#threading.Thread>`_ be called. To invoke a parent, common syntax is ``Thread.__init__(self, kwargs)``. This has several problems, however; use the (awkward) `super <https://docs.python.org/2/library/functions.html#super>`_ syntax instead. Note that this syntax is much improved in Python 3 -- simply use `super().__init__(kwargs) <https://docs.python.org/3/library/functions.html#super>`_.
# ``Thread.__init__`` `must <https://docs.python.org/2/library/threading.html#threading.Thread>`_
# be called. To invoke a parent, common syntax is
# ``Thread.__init__(self, kwargs)``. This has several problems, however;
# use the (awkward) `super <https://docs.python.org/2/library/functions.html#super>`_
# syntax below instead. Note that this syntax is much improved in
# Python 3 -- simply use `super().__init__(kwargs) <https://docs.python.org/3/library/functions.html#super>`_.
super(CounterThread, self).__init__(**kwargs)
self._wait_time_sec = wait_time_sec
self._number_factory = number_factory

# `This method <https://docs.python.org/2/library/threading.html#threading.Thread.run>`_ runs in a separate thread.
# `This method <https://docs.python.org/2/library/threading.html#threading.Thread.run>`_
# runs in a separate thread.
def run(self):
for index in range(10):
sleep(self._wait_time_sec)
Expand All @@ -55,7 +63,8 @@ def run(self):
def main():
# Create two threads.
#
# Use a `lock <https://docs.python.org/2/library/threading.html#lock-objects>`_ to enforce exclusive access in the NumberFactory.
# Use a `lock <https://docs.python.org/2/library/threading.html#lock-objects>`_
# to enforce exclusive access in the NumberFactory.
lock = Lock()
nf = NumberFactory(lock)
ct1 = CounterThread(1.0, nf, name='Slow')
Expand Down

0 comments on commit 2dcb8d5

Please sign in to comment.