Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix literalincludes #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Concurrency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Working with Threads
--------------------

Creating threads is easy, perhaps too easy. This example downloads a
web page concurrently::
web page concurrently:

.. literalinclude:: src/chapter19/test_thread_creation.py

Expand Down Expand Up @@ -277,7 +277,7 @@ It may still make sense to defer your imports. Such deferral can
decrease the start time of your app. Just keep in mind that thread(s)
performing such imports will be forced to run single threaded because
of this lock. So it might make sense for your code to perform deferred
imports in a background thread::
imports in a background thread:

.. literalinclude:: src/chapter19/background_import.py

Expand Down Expand Up @@ -327,7 +327,7 @@ that task. If it's not ready, a wait-on dependency is introduced.
We are going to look at how we can use this functionality by using the
example of downloading web pages. We will wrap this up so it's easy to
work with, tracking the state of the download, as well as any timing
information::
information:

.. literalinclude:: src/chapter19/downloader.py

Expand All @@ -348,7 +348,7 @@ caller. This exception will be one of:
similar to how a coroutine works when ``send`` is called on it.)

Now we have what we need to multiplex the downloads of several web
pages over a thread pool::
pages over a thread pool:

.. literalinclude:: src/chapter19/test_futures.py

Expand All @@ -362,7 +362,7 @@ Shutting down a thread pool should be as simple as calling the
account this shutdown can happen during extraordinary times in your
code. Here's the Jython version of a robust shutdown function,
``shutdown_and_await_termination``, as provided in the standard Java
docs::
docs:

.. literalinclude:: src/chapter19/shutdown.py

Expand All @@ -371,7 +371,7 @@ working with futures. The scenario is that instead of waiting for all the
futures to complete, as our code did with ``invokeAll``, or otherwise
polling them, the completion service will push futures as they are
completed onto a synchronized queue. This queue can then be consumed,
by consumers running in one or more threads::
by consumers running in one or more threads:

.. literalinclude:: src/chapter19/test_completion.py

Expand Down Expand Up @@ -427,7 +427,7 @@ need to consider thread safety if it will be both shared and mutated.

Here's a simple test harness we will use in our
examples. ``ThreadSafetyTestCase`` subclasses ``unittest.TestCase``,
adding a new method ``assertContended``::
adding a new method ``assertContended``:

.. literalinclude:: src/chapter19/threadsafety.py

Expand All @@ -439,7 +439,7 @@ For example, we use this idea in Jython to test that certain
operations on the ``list`` type are atomic. The idea is to to apply a
sequence of operations that perform an operation, then reverse it. One
step forward, one step back. The net result should be right where you
started, an empty list, which is what the test code asserts::
started, an empty list, which is what the test code asserts:

.. literalinclude:: src/chapter19/test_list.py

Expand Down Expand Up @@ -480,12 +480,12 @@ with-statement; failing that, you must use a try-finally to ensure
that the lock is always released when exiting a block of code.

Here's some example code using the with-statement. The code allocates
a lock, then shares it amongst some tasks::
a lock, then shares it amongst some tasks:

.. literalinclude:: src/chapter19/test_lock.py
:pyobject: LockTestCase.test_with_lock

Alternatively, you can do this with try-finally::
Alternatively, you can do this with try-finally:

.. literalinclude:: src/chapter19/test_lock.py
:pyobject: LockTestCase.test_try_finally_lock
Expand All @@ -497,7 +497,7 @@ code.
Another possibility is to use the ``synchronize`` module, which is
specific to Jython. This module provides a``make_synchronized``
decorator function, which wraps any callable in Jython in a
``synchronized`` block::
``synchronized`` block:

.. literalinclude:: src/chapter19/test_synchronized.py

Expand Down Expand Up @@ -536,7 +536,7 @@ Deadlocks
~~~~~~~~~

But use synchronizaton carefully. This code will always eventually
deadlock::
deadlock:

.. literalinclude:: src/chapter19/deadlock.py

Expand Down Expand Up @@ -587,7 +587,7 @@ For example, here's how we actually implement a ``Queue`` in the
standard library of Jython (just modified here to use the
with-statement). We can't use a standard Java blocking queue, because
the requirement of being able to join on the queue when there's no
more work to be performed requires a third condition variable::
more work to be performed requires a third condition variable:

.. literalinclude:: src/chapter19/Queue.py

Expand Down Expand Up @@ -827,7 +827,7 @@ before we even consider changing its implementation and removing
``_thread``.

So here's how we can monkey patch, following a recipe of
Guido van Rossum::
Guido van Rossum:

.. literalinclude:: src/chapter19/monkeypatch.py

Expand All @@ -839,7 +839,7 @@ essentially a bug fix like this one. In our case, we will use a
variant, the ``monkeypatch_method_if_not_set`` decorator, to ensure we
only patch if it has not been fixed by a later version.

Putting it all together, we have this code::
Putting it all together, we have this code:

.. literalinclude:: src/chapter19/interrupt.py

Expand Down