⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module-threading.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>7.5 threading -- Higher-level threading interface</title>
<META NAME="description" CONTENT="7.5 threading -- Higher-level threading interface">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-mutex.html" tppabs="http://www.python.org/doc/current/lib/module-mutex.html">
<LINK REL="previous" href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html">
<LINK REL="up" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">
<LINK REL="next" href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html">7.4 thread  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html">7.5.1 Lock Objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION009500000000000000000">
7.5 <tt class="module">threading</tt> --
         Higher-level threading interface</A>
</H1>

<P>


<P>
This module constructs higher-level threading interfaces on top of the 
lower level <tt class='module'><a href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html">thread</a></tt> module.

<P>
This module is safe for use with "<tt class="samp">from threading import *</tt>".  It
defines the following functions and objects:

<P>
<dl><dt><b><a name='l2h-1634'><tt class='function'>activeCount</tt></a></b> ()
<dd>
Return the number of currently active <tt class="class">Thread</tt> objects.
The returned count is equal to the length of the list returned by
<tt class="function">enumerate()</tt>.
A function that returns the number of currently active threads.
</dl>

<P>
<dl><dt><b><a name='l2h-1635'><tt class='function'>Condition</tt></a></b> ()
<dd>
A factory function that returns a new condition variable object.
A condition variable allows one or more threads to wait until they
are notified by another thread.
</dl>

<P>
<dl><dt><b><a name='l2h-1636'><tt class='function'>currentThread</tt></a></b> ()
<dd>
Return the current <tt class="class">Thread</tt> object, corresponding to the
caller's thread of control.  If the caller's thread of control was not
created through the
<tt class="module">threading</tt> module, a dummy thread object with limited functionality
is returned.
</dl>

<P>
<dl><dt><b><a name='l2h-1637'><tt class='function'>enumerate</tt></a></b> ()
<dd>
Return a list of all currently active <tt class="class">Thread</tt> objects.
The list includes daemonic threads, dummy thread objects created
by <tt class="function">currentThread()</tt>, and the main thread.  It excludes terminated
threads and threads that have not yet been started.
</dl>

<P>
<dl><dt><b><a name='l2h-1638'><tt class='function'>Event</tt></a></b> ()
<dd>
A factory function that returns a new event object.  An event
manages a flag that can be set to true with the <tt class="method">set()</tt> method and
reset to false with the <tt class="method">clear()</tt> method.  The <tt class="method">wait()</tt> method blocks
until the flag is true.
</dl>

<P>
<dl><dt><b><a name='l2h-1639'><tt class='function'>Lock</tt></a></b> ()
<dd>
A factory function that returns a new primitive lock object.  Once
a thread has acquired it, subsequent attempts to acquire it block,
until it is released; any thread may release it.
</dl>

<P>
<dl><dt><b><a name='l2h-1640'><tt class='function'>RLock</tt></a></b> ()
<dd>
A factory function that returns a new reentrant lock object.
A reentrant lock must be released by the thread that acquired it.
Once a thread has acquired a reentrant lock, the same thread may
acquire it again without blocking; the thread must release it once
for each time it has acquired it.
</dl>

<P>
<dl><dt><b><a name='l2h-1641'><tt class='function'>Semaphore</tt></a></b> ()
<dd>
A factory function that returns a new semaphore object.  A
semaphore manages a counter representing the number of <tt class="method">release()</tt>
calls minus the number of <tt class="method">acquire()</tt> calls, plus an initial value.
The <tt class="method">acquire()</tt> method blocks if necessary until it can return
without making the counter negative.
</dl>

<P>
<dl><dt><b><a name='l2h-1642'><tt class='class'>Thread</tt></a></b> ()
<dd>
A class that represents a thread of control.  This class can be safely subclassed in a limited fashion.
</dl>

<P>
Detailed interfaces for the objects are documented below.  

<P>
The design of this module is loosely based on Java's threading model.
However, where Java makes locks and condition variables basic behavior
of every object, they are separate objects in Python.  Python's <tt class="class">Thread</tt>
class supports a subset of the behavior of Java's Thread class;
currently, there are no priorities, no thread groups, and threads
cannot be destroyed, stopped, suspended, resumed, or interrupted.  The
static methods of Java's Thread class, when implemented, are mapped to
module-level functions.

<P>
All of the methods described below are executed atomically.

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html2906"
  href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html">7.5.1 Lock Objects </A>
<LI><A NAME="tex2html2907"
  href="rlock-objects.html" tppabs="http://www.python.org/doc/current/lib/rlock-objects.html">7.5.2 RLock Objects </A>
<LI><A NAME="tex2html2908"
  href="condition-objects.html" tppabs="http://www.python.org/doc/current/lib/condition-objects.html">7.5.3 Condition Objects </A>
<LI><A NAME="tex2html2909"
  href="semaphore-objects.html" tppabs="http://www.python.org/doc/current/lib/semaphore-objects.html">7.5.4 Semaphore Objects </A>
<LI><A NAME="tex2html2910"
  href="event-objects.html" tppabs="http://www.python.org/doc/current/lib/event-objects.html">7.5.5 Event Objects </A>
<LI><A NAME="tex2html2911"
  href="thread-objects.html" tppabs="http://www.python.org/doc/current/lib/thread-objects.html">7.5.6 Thread Objects </A>
</UL>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-thread.html" tppabs="http://www.python.org/doc/current/lib/module-thread.html">7.4 thread  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="someos.html" tppabs="http://www.python.org/doc/current/lib/someos.html">7. Optional Operating System</A>
<b class="navlabel">Next:</b> <a class="sectref" href="lock-objects.html" tppabs="http://www.python.org/doc/current/lib/lock-objects.html">7.5.1 Lock Objects</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -