Kaydet (Commit) 12686783 authored tarafından Fred Drake's avatar Fred Drake

Adjust some poor wording in the text that explains what events are used

for (reported by Keith Briggs).
Wrap some very long lines.
üst 2f31d561
...@@ -40,10 +40,10 @@ threads and threads that have not yet been started. ...@@ -40,10 +40,10 @@ threads and threads that have not yet been started.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{Event}{} \begin{funcdesc}{Event}{}
A factory function that returns a new event object. An event A factory function that returns a new event object. An event manages
manages a flag that can be set to true with the \method{set()} method and a flag that can be set to true with the \method{set()} method and
reset to false with the \method{clear()} method. The \method{wait()} method blocks reset to false with the \method{clear()} method. The \method{wait()}
until the flag is true. method blocks until the flag is true.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{Lock}{} \begin{funcdesc}{Lock}{}
...@@ -79,7 +79,8 @@ semaphore is released too many times it's a sign of a bug. If not given, ...@@ -79,7 +79,8 @@ semaphore is released too many times it's a sign of a bug. If not given,
\end{funcdesc} \end{funcdesc}
\begin{classdesc*}{Thread}{} \begin{classdesc*}{Thread}{}
A class that represents a thread of control. This class can be safely subclassed in a limited fashion. A class that represents a thread of control. This class can be safely
subclassed in a limited fashion.
\end{classdesc*} \end{classdesc*}
\begin{classdesc*}{Timer}{} \begin{classdesc*}{Timer}{}
...@@ -409,15 +410,15 @@ The use of a bounded semaphore reduces the chance that a programming error ...@@ -409,15 +410,15 @@ The use of a bounded semaphore reduces the chance that a programming error
which causes the semaphore to be released more than it's acquired will go which causes the semaphore to be released more than it's acquired will go
undetected. undetected.
\subsection{Event Objects \label{event-objects}} \subsection{Event Objects \label{event-objects}}
This is one of the simplest mechanisms for communication between This is one of the simplest mechanisms for communication between
threads: one thread signals an event and one or more other threads threads: one thread signals an event and other threads wait for it.
are waiting for it.
An event object manages an internal flag that can be set to true with An event object manages an internal flag that can be set to true with
the \method{set()} method and reset to false with the \method{clear()} method. The the \method{set()} method and reset to false with the \method{clear()}
\method{wait()} method blocks until the flag is true. method. The \method{wait()} method blocks until the flag is true.
\begin{classdesc}{Event}{} \begin{classdesc}{Event}{}
...@@ -437,8 +438,8 @@ at all. ...@@ -437,8 +438,8 @@ at all.
\begin{methoddesc}{clear}{} \begin{methoddesc}{clear}{}
Reset the internal flag to false. Reset the internal flag to false.
Subsequently, threads calling \method{wait()} will block until \method{set()} is Subsequently, threads calling \method{wait()} will block until
called to set the internal flag to true again. \method{set()} is called to set the internal flag to true again.
\end{methoddesc} \end{methoddesc}
\begin{methoddesc}{wait}{\optional{timeout}} \begin{methoddesc}{wait}{\optional{timeout}}
...@@ -542,10 +543,10 @@ separate thread of control. ...@@ -542,10 +543,10 @@ separate thread of control.
Method representing the thread's activity. Method representing the thread's activity.
You may override this method in a subclass. The standard You may override this method in a subclass. The standard
\method{run()} method invokes the callable object passed to the object's constructor as the \method{run()} method invokes the callable object passed to the
\var{target} argument, if any, with sequential and keyword object's constructor as the \var{target} argument, if any, with
arguments taken from the \var{args} and \var{kwargs} arguments, sequential and keyword arguments taken from the \var{args} and
respectively. \var{kwargs} arguments, respectively.
\end{methoddesc} \end{methoddesc}
\begin{methoddesc}{join}{\optional{timeout}} \begin{methoddesc}{join}{\optional{timeout}}
...@@ -554,8 +555,8 @@ This blocks the calling thread until the thread whose \method{join()} ...@@ -554,8 +555,8 @@ This blocks the calling thread until the thread whose \method{join()}
method is called terminates -- either normally or through an method is called terminates -- either normally or through an
unhandled exception -- or until the optional timeout occurs. unhandled exception -- or until the optional timeout occurs.
When the \var{timeout} argument is present and not \code{None}, it should When the \var{timeout} argument is present and not \code{None}, it
be a floating point number specifying a timeout for the should be a floating point number specifying a timeout for the
operation in seconds (or fractions thereof). operation in seconds (or fractions thereof).
A thread can be \method{join()}ed many times. A thread can be \method{join()}ed many times.
...@@ -603,15 +604,16 @@ threads are left. ...@@ -603,15 +604,16 @@ threads are left.
\subsection{Timer Objects \label{timer-objects}} \subsection{Timer Objects \label{timer-objects}}
This class represents an action that should be run only after a certain amount This class represents an action that should be run only after a
of time has passed --- a timer. \class{Timer} is a subclass of \class{Thread} and certain amount of time has passed --- a timer. \class{Timer} is a
as such also functions as an example of creating custom threads. subclass of \class{Thread} and as such also functions as an example of
creating custom threads.
Timers are started, as with threads, by calling their \method{start()} method. The Timers are started, as with threads, by calling their \method{start()}
timer can be stopped (before its action has begun) by calling the method. The timer can be stopped (before its action has begun) by
\method{cancel()} method. The interval the timer will wait before executing calling the \method{cancel()} method. The interval the timer will
its action may not be exactly the same as the interval specified by the wait before executing its action may not be exactly the same as the
user. interval specified by the user.
For example: For example:
\begin{verbatim} \begin{verbatim}
...@@ -628,6 +630,6 @@ keyword arguments \var{kwargs}, after \var{interval} seconds have passed. ...@@ -628,6 +630,6 @@ keyword arguments \var{kwargs}, after \var{interval} seconds have passed.
\end{classdesc} \end{classdesc}
\begin{methoddesc}{cancel}{} \begin{methoddesc}{cancel}{}
Stop the timer, and cancel the execution of the timer's action. This will only Stop the timer, and cancel the execution of the timer's action. This
work if the timer is still in its waiting stage. will only work if the timer is still in its waiting stage.
\end{methoddesc} \end{methoddesc}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment