~ubuntu-branches/ubuntu/precise/python-qt4/precise-proposed

« back to all changes in this revision

Viewing changes to doc/html/qthreadpool.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell, Jonathan Riddell
  • Date: 2010-11-08 16:13:33 UTC
  • mfrom: (1.5.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101108161333-0nec4wu0nz3wpf9r
Tags: 4.8.1-0ubuntu1
[ Jonathan Riddell ]
* New upstream release
* Build against python-sip-dev 4.11.2
* Remove kubuntu_02_fix-scpk-and-flag-issue.diff merged upstream
* Install __init__.py into /usr/lib/python3.2/dist-packages/PyQt4,
  fixes Python 3 support
* Add QtDeclarative to python-qt4
* Add kubuntu_03_uiparser.diff from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
tr.address { font-family: sans-serif }
8
8
body { background: #ffffff; color: black; }
9
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QThreadPool Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QThreadPool class manages a collection of QThreads. <a href="#details">More...</a></p>
 
10
 
10
11
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qthreadpool.html#QThreadPool">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />int <b><a href="qthreadpool.html#activeThreadCount">activeThreadCount</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qthreadpool.html#expiryTimeout">expiryTimeout</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qthreadpool.html#maxThreadCount">maxThreadCount</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qthreadpool.html#releaseThread">releaseThread</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qthreadpool.html#reserveThread">reserveThread</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qthreadpool.html#setExpiryTimeout">setExpiryTimeout</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qthreadpool.html#setMaxThreadCount">setMaxThreadCount</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qthreadpool.html#start">start</a></b> (<i>self</i>, QRunnable, int&#160;<i>priority</i>&#160;=&#160;0)</li><li><div class="fn" />bool <b><a href="qthreadpool.html#tryStart">tryStart</a></b> (<i>self</i>, QRunnable)</li><li><div class="fn" /><b><a href="qthreadpool.html#waitForDone">waitForDone</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QThreadPool <b><a href="qthreadpool.html#globalInstance">globalInstance</a></b> ()</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QThreadPool class manages a collection of QThreads.</p>
11
 
<p>QThreadPool manages and recyles individual <a href="qthread.html">QThread</a> objects to help reduce thread creation costs in programs that use threads. Each Qt application has one global QThreadPool object, which can be accessed by calling <a href="qthreadpool.html#globalInstance">globalInstance</a>().</p>
12
 
<p>To use one of the QThreadPool threads, subclass <a href="qrunnable.html">QRunnable</a> and implement the run() virtual function. Then create an object of that class and pass it to <a href="qthreadpool.html#start">QThreadPool.start</a>().</p>
13
 
<pre> class HelloWorldTask : public QRunnable
 
12
<p>QThreadPool manages and recyles individual <a href="qthread.html">QThread</a> objects to help reduce thread creation
 
13
costs in programs that use threads. Each Qt application has one
 
14
global QThreadPool object, which can be accessed by calling
 
15
<a href="qthreadpool.html#globalInstance">globalInstance</a>().</p>
 
16
<p>To use one of the QThreadPool threads, subclass <a href="qrunnable.html">QRunnable</a> and implement the run() virtual
 
17
function. Then create an object of that class and pass it to
 
18
<a href="qthreadpool.html#start">QThreadPool.start</a>().</p>
 
19
<pre class="highlightedCode brush: cpp">
 
20
 class HelloWorldTask : public QRunnable
14
21
 {
15
22
     void run()
16
23
     {
20
27
 
21
28
 HelloWorldTask *hello = new HelloWorldTask();
22
29
<span class="comment"> // QThreadPool takes ownership and deletes 'hello' automatically</span>
23
 
 QThreadPool.globalInstance()-&gt;start(hello);</pre>
24
 
<p>QThreadPool deletes the <a href="qrunnable.html">QRunnable</a> automatically by default. Use <a href="qrunnable.html#setAutoDelete">QRunnable.setAutoDelete</a>() to change the auto-deletion flag.</p>
25
 
<p>QThreadPool supports executing the same <a href="qrunnable.html">QRunnable</a> more than once by calling tryStart(this) from within <a href="qrunnable.html#run">QRunnable.run</a>(). If autoDelete is enabled the <a href="qrunnable.html">QRunnable</a> will be deleted when the last thread exits the run function. Calling <a href="qthreadpool.html#start">start</a>() multiple times with the same <a href="qrunnable.html">QRunnable</a> when autoDelete is enabled creates a race condition and is not recommended.</p>
26
 
<p>Threads that are unused for a certain amount of time will expire. The default expiry timeout is 30000 milliseconds (30 seconds). This can be changed using <a href="qthreadpool.html#expiryTimeout-prop">setExpiryTimeout</a>(). Setting a negative expiry timeout disables the expiry mechanism.</p>
27
 
<p>Call <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() to query the maximum number of threads to be used. If needed, you can change the limit with <a href="qthreadpool.html#maxThreadCount-prop">setMaxThreadCount</a>(). The default <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() is <a href="qthread.html#idealThreadCount">QThread.idealThreadCount</a>(). The <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>() function returns the number of threads currently doing work.</p>
28
 
<p>The <a href="qthreadpool.html#reserveThread">reserveThread</a>() function reserves a thread for external use. Use <a href="qthreadpool.html#releaseThread">releaseThread</a>() when your are done with the thread, so that it may be reused. Essentially, these functions temporarily increase or reduce the active thread count and are useful when implementing time-consuming operations that are not visible to the QThreadPool.</p>
29
 
<p>Note that QThreadPool is a low-level class for managing threads, see <a href="qtconcurrentrun.html#run">QtConcurrent.run</a>() or the other <a href="threads-qtconcurrent.html">Qt Concurrent</a> APIs for higher level alternatives.</p>
30
 
<p>See also <a href="qrunnable.html">QRunnable</a>.</p>
 
30
 QThreadPool.globalInstance()-&gt;start(hello);
 
31
</pre>
 
32
<p>QThreadPool deletes the <a href="qrunnable.html">QRunnable</a>
 
33
automatically by default. Use <a href="qrunnable.html#setAutoDelete">QRunnable.setAutoDelete</a>() to
 
34
change the auto-deletion flag.</p>
 
35
<p>QThreadPool supports executing the same <a href="qrunnable.html">QRunnable</a> more than once by calling
 
36
tryStart(this) from within <a href="qrunnable.html#run">QRunnable.run</a>(). If autoDelete is enabled
 
37
the <a href="qrunnable.html">QRunnable</a> will be deleted when the
 
38
last thread exits the run function. Calling <a href="qthreadpool.html#start">start</a>() multiple times with the same
 
39
<a href="qrunnable.html">QRunnable</a> when autoDelete is enabled
 
40
creates a race condition and is not recommended.</p>
 
41
<p>Threads that are unused for a certain amount of time will
 
42
expire. The default expiry timeout is 30000 milliseconds (30
 
43
seconds). This can be changed using <a href="qthreadpool.html#expiryTimeout-prop">setExpiryTimeout</a>().
 
44
Setting a negative expiry timeout disables the expiry
 
45
mechanism.</p>
 
46
<p>Call <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() to
 
47
query the maximum number of threads to be used. If needed, you can
 
48
change the limit with <a href="qthreadpool.html#maxThreadCount-prop">setMaxThreadCount</a>(). The
 
49
default <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() is
 
50
<a href="qthread.html#idealThreadCount">QThread.idealThreadCount</a>().
 
51
The <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>()
 
52
function returns the number of threads currently doing work.</p>
 
53
<p>The <a href="qthreadpool.html#reserveThread">reserveThread</a>()
 
54
function reserves a thread for external use. Use <a href="qthreadpool.html#releaseThread">releaseThread</a>() when your are
 
55
done with the thread, so that it may be reused. Essentially, these
 
56
functions temporarily increase or reduce the active thread count
 
57
and are useful when implementing time-consuming operations that are
 
58
not visible to the QThreadPool.</p>
 
59
<p>Note that QThreadPool is a low-level class for managing threads,
 
60
see <a href="qtconcurrentrun.html#run">QtConcurrent.run</a>() or
 
61
the other <a href="threads-qtconcurrent.html">Qt Concurrent</a>
 
62
APIs for higher level alternatives.</p>
31
63
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QThreadPool" />QThreadPool.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a thread pool with the given <i>parent</i>.</p>
32
 
<a name="//apple_ref/cpp/instm/QThreadPool/~QThreadPool" />
33
 
<h3 class="fn"><a name="activeThreadCount" />int QThreadPool.activeThreadCount (<i>self</i>)</h3><h3 class="fn"><a name="expiryTimeout" />int QThreadPool.expiryTimeout (<i>self</i>)</h3><h3 class="fn"><a name="globalInstance" /><a href="qthreadpool.html">QThreadPool</a> QThreadPool.globalInstance ()</h3><p>Returns the global <a href="qthreadpool.html">QThreadPool</a> instance.</p>
34
 
<a name="//apple_ref/cpp/instm/QThreadPool/releaseThread" />
 
64
 
 
65
 
 
66
<h3 class="fn"><a name="activeThreadCount" />int QThreadPool.activeThreadCount (<i>self</i>)</h3><h3 class="fn"><a name="expiryTimeout" />int QThreadPool.expiryTimeout (<i>self</i>)</h3><h3 class="fn"><a name="globalInstance" /><a href="qthreadpool.html">QThreadPool</a> QThreadPool.globalInstance ()</h3><p>Returns the global <a href="qthreadpool.html">QThreadPool</a>
 
67
instance.</p>
 
68
 
 
69
 
35
70
<h3 class="fn"><a name="maxThreadCount" />int QThreadPool.maxThreadCount (<i>self</i>)</h3><h3 class="fn"><a name="releaseThread" />QThreadPool.releaseThread (<i>self</i>)</h3><p>Releases a thread previously reserved by a call to <a href="qthreadpool.html#reserveThread">reserveThread</a>().</p>
36
 
<p><b>Note:</b> Calling this function without previously reserving a thread temporarily increases <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>(). This is useful when a thread goes to sleep waiting for more work, allowing other threads to continue. Be sure to call <a href="qthreadpool.html#reserveThread">reserveThread</a>() when done waiting, so that the thread pool can correctly maintain the <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>().</p>
 
71
<p><b>Note:</b> Calling this function without previously reserving
 
72
a thread temporarily increases <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>(). This
 
73
is useful when a thread goes to sleep waiting for more work,
 
74
allowing other threads to continue. Be sure to call <a href="qthreadpool.html#reserveThread">reserveThread</a>() when done
 
75
waiting, so that the thread pool can correctly maintain the
 
76
<a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>().</p>
37
77
<p>See also <a href="qthreadpool.html#reserveThread">reserveThread</a>().</p>
38
 
<a name="//apple_ref/cpp/instm/QThreadPool/reserveThread" />
39
 
<h3 class="fn"><a name="reserveThread" />QThreadPool.reserveThread (<i>self</i>)</h3><p>Reserves one thread, disregarding <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>() and <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>().</p>
40
 
<p>Once you are done with the thread, call <a href="qthreadpool.html#releaseThread">releaseThread</a>() to allow it to be reused.</p>
41
 
<p><b>Note:</b> This function will always increase the number of active threads. This means that by using this function, it is possible for <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>() to return a value greater than <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() .</p>
 
78
 
 
79
 
 
80
<h3 class="fn"><a name="reserveThread" />QThreadPool.reserveThread (<i>self</i>)</h3><p>Reserves one thread, disregarding <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>()
 
81
and <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>().</p>
 
82
<p>Once you are done with the thread, call <a href="qthreadpool.html#releaseThread">releaseThread</a>() to allow it to
 
83
be reused.</p>
 
84
<p><b>Note:</b> This function will always increase the number of
 
85
active threads. This means that by using this function, it is
 
86
possible for <a href="qthreadpool.html#activeThreadCount-prop">activeThreadCount</a>()
 
87
to return a value greater than <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>() .</p>
42
88
<p>See also <a href="qthreadpool.html#releaseThread">releaseThread</a>().</p>
43
 
<a name="//apple_ref/cpp/instm/QThreadPool/start" />
44
 
<h3 class="fn"><a name="setExpiryTimeout" />QThreadPool.setExpiryTimeout (<i>self</i>, int)</h3><h3 class="fn"><a name="setMaxThreadCount" />QThreadPool.setMaxThreadCount (<i>self</i>, int)</h3><h3 class="fn"><a name="start" />QThreadPool.start (<i>self</i>, <a href="qrunnable.html">QRunnable</a>, int&#160;<i>priority</i>&#160;=&#160;0)</h3><p>Reserves a thread and uses it to run <i>runnable</i>, unless this thread will make the current thread count exceed <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>(). In that case, <i>runnable</i> is added to a run queue instead. The <i>priority</i> argument can be used to control the run queue's order of execution.</p>
45
 
<p>Note that the thread pool takes ownership of the <i>runnable</i> if <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns true, and the <i>runnable</i> will be deleted automatically by the thread pool after the <a href="qrunnable.html#run">runnable-&gt;run()</a> returns. If <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns false, ownership of <i>runnable</i> remains with the caller. Note that changing the auto-deletion on <i>runnable</i> after calling this functions results in undefined behavior.</p>
46
 
<a name="//apple_ref/cpp/instm/QThreadPool/tryStart" />
 
89
 
 
90
 
 
91
<h3 class="fn"><a name="setExpiryTimeout" />QThreadPool.setExpiryTimeout (<i>self</i>, int)</h3><h3 class="fn"><a name="setMaxThreadCount" />QThreadPool.setMaxThreadCount (<i>self</i>, int)</h3><h3 class="fn"><a name="start" />QThreadPool.start (<i>self</i>, <a href="qrunnable.html">QRunnable</a>, int&#160;<i>priority</i>&#160;=&#160;0)</h3><p>Reserves a thread and uses it to run <i>runnable</i>, unless
 
92
this thread will make the current thread count exceed <a href="qthreadpool.html#maxThreadCount-prop">maxThreadCount</a>(). In
 
93
that case, <i>runnable</i> is added to a run queue instead. The
 
94
<i>priority</i> argument can be used to control the run queue's
 
95
order of execution.</p>
 
96
<p>Note that the thread pool takes ownership of the <i>runnable</i>
 
97
if <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns
 
98
true, and the <i>runnable</i> will be deleted automatically by the
 
99
thread pool after the <a href="qrunnable.html#run">runnable-&gt;run()</a> returns. If <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns
 
100
false, ownership of <i>runnable</i> remains with the caller. Note
 
101
that changing the auto-deletion on <i>runnable</i> after calling
 
102
this functions results in undefined behavior.</p>
 
103
 
 
104
 
47
105
<h3 class="fn"><a name="tryStart" />bool QThreadPool.tryStart (<i>self</i>, <a href="qrunnable.html">QRunnable</a>)</h3><p>Attempts to reserve a thread to run <i>runnable</i>.</p>
48
 
<p>If no threads are available at the time of calling, then this function does nothing and returns false. Otherwise, <i>runnable</i> is run immediately using one available thread and this function returns true.</p>
49
 
<p>Note that the thread pool takes ownership of the <i>runnable</i> if <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns true, and the <i>runnable</i> will be deleted automatically by the thread pool after the <a href="qrunnable.html#run">runnable-&gt;run()</a> returns. If <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns false, ownership of <i>runnable</i> remains with the caller. Note that changing the auto-deletion on <i>runnable</i> after calling this function results in undefined behavior.</p>
50
 
<a name="//apple_ref/cpp/instm/QThreadPool/waitForDone" />
51
 
<h3 class="fn"><a name="waitForDone" />QThreadPool.waitForDone (<i>self</i>)</h3><p>Waits for each thread to exit and removes all threads from the thread pool.</p>
52
 
<p /><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.7.7 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt&#160;4.6.3</td></tr></table></div></address></body></html>
 
 
b'\\ No newline at end of file'
 
106
<p>If no threads are available at the time of calling, then this
 
107
function does nothing and returns false. Otherwise, <i>runnable</i>
 
108
is run immediately using one available thread and this function
 
109
returns true.</p>
 
110
<p>Note that the thread pool takes ownership of the <i>runnable</i>
 
111
if <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns
 
112
true, and the <i>runnable</i> will be deleted automatically by the
 
113
thread pool after the <a href="qrunnable.html#run">runnable-&gt;run()</a> returns. If <a href="qrunnable.html#autoDelete">runnable-&gt;autoDelete()</a> returns
 
114
false, ownership of <i>runnable</i> remains with the caller. Note
 
115
that changing the auto-deletion on <i>runnable</i> after calling
 
116
this function results in undefined behavior.</p>
 
117
 
 
118
 
 
119
<h3 class="fn"><a name="waitForDone" />QThreadPool.waitForDone (<i>self</i>)</h3><p>Waits for each thread to exit and removes all threads from the
 
120
thread pool.</p>
 
121
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.8.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt&#160;4.7.0</td></tr></table></div></address></body></html>
 
 
b'\\ No newline at end of file'