|
@@ -0,0 +1,743 @@
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+<!DOCTYPE html>
|
|
4
|
+<html class="writer-html4" lang="en" >
|
|
5
|
+<head>
|
|
6
|
+ <meta charset="utf-8">
|
|
7
|
+
|
|
8
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
9
|
+
|
|
10
|
+ <title>Welcome to task’s documentation! — task documentation</title>
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+ <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
15
|
+ <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+ <!--[if lt IE 9]>
|
|
24
|
+ <script src="_static/js/html5shiv.min.js"></script>
|
|
25
|
+ <![endif]-->
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+ <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
|
29
|
+ <script type="text/javascript" src="_static/jquery.js"></script>
|
|
30
|
+ <script type="text/javascript" src="_static/underscore.js"></script>
|
|
31
|
+ <script type="text/javascript" src="_static/doctools.js"></script>
|
|
32
|
+ <script type="text/javascript" src="_static/language_data.js"></script>
|
|
33
|
+
|
|
34
|
+ <script type="text/javascript" src="_static/js/theme.js"></script>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+ <link rel="index" title="Index" href="genindex.html" />
|
|
38
|
+ <link rel="search" title="Search" href="search.html" />
|
|
39
|
+</head>
|
|
40
|
+
|
|
41
|
+<body class="wy-body-for-nav">
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+ <div class="wy-grid-for-nav">
|
|
45
|
+
|
|
46
|
+ <nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
47
|
+ <div class="wy-side-scroll">
|
|
48
|
+ <div class="wy-side-nav-search" >
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+ <a href="#" class="icon icon-home" alt="Documentation Home"> task
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+ </a>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+<div role="search">
|
|
65
|
+ <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
66
|
+ <input type="text" name="q" placeholder="Search docs" />
|
|
67
|
+ <input type="hidden" name="check_keywords" value="yes" />
|
|
68
|
+ <input type="hidden" name="area" value="default" />
|
|
69
|
+ </form>
|
|
70
|
+</div>
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+ </div>
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+ <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+ <!-- Local TOC -->
|
|
84
|
+ <div class="local-toc"><ul>
|
|
85
|
+<li><a class="reference internal" href="#">Welcome to task’s documentation!</a><ul>
|
|
86
|
+<li><a class="reference internal" href="#task-task-module">task (Task Module)</a></li>
|
|
87
|
+</ul>
|
|
88
|
+</li>
|
|
89
|
+<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
|
|
90
|
+</ul>
|
|
91
|
+</div>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+ </div>
|
|
95
|
+
|
|
96
|
+ </div>
|
|
97
|
+ </nav>
|
|
98
|
+
|
|
99
|
+ <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+ <nav class="wy-nav-top" aria-label="top navigation">
|
|
103
|
+
|
|
104
|
+ <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
|
105
|
+ <a href="#">task</a>
|
|
106
|
+
|
|
107
|
+ </nav>
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+ <div class="wy-nav-content">
|
|
111
|
+
|
|
112
|
+ <div class="rst-content">
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+<div role="navigation" aria-label="breadcrumbs navigation">
|
|
131
|
+
|
|
132
|
+ <ul class="wy-breadcrumbs">
|
|
133
|
+
|
|
134
|
+ <li><a href="#" class="icon icon-home"></a> »</li>
|
|
135
|
+
|
|
136
|
+ <li>Welcome to task’s documentation!</li>
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+ <li class="wy-breadcrumbs-aside">
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+ <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+ </li>
|
|
146
|
+
|
|
147
|
+ </ul>
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+ <hr/>
|
|
151
|
+</div>
|
|
152
|
+ <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
153
|
+ <div itemprop="articleBody">
|
|
154
|
+
|
|
155
|
+ <div class="section" id="module-task">
|
|
156
|
+<span id="welcome-to-task-s-documentation"></span><h1>Welcome to task’s documentation!<a class="headerlink" href="#module-task" title="Permalink to this headline">¶</a></h1>
|
|
157
|
+<div class="section" id="task-task-module">
|
|
158
|
+<h2>task (Task Module)<a class="headerlink" href="#task-task-module" title="Permalink to this headline">¶</a></h2>
|
|
159
|
+<p><strong>Author:</strong></p>
|
|
160
|
+<ul class="simple">
|
|
161
|
+<li>Dirk Alders <<a class="reference external" href="mailto:sudo-dirk%40mount-mockery.de">sudo-dirk<span>@</span>mount-mockery<span>.</span>de</a>></li>
|
|
162
|
+</ul>
|
|
163
|
+<p><strong>Description:</strong></p>
|
|
164
|
+<blockquote>
|
|
165
|
+<div>This Module supports helpfull classes for queues, tasks, …</div></blockquote>
|
|
166
|
+<p><strong>Submodules:</strong></p>
|
|
167
|
+<ul class="simple">
|
|
168
|
+<li><a class="reference internal" href="#task.crontab" title="task.crontab"><code class="xref py py-class docutils literal notranslate"><span class="pre">task.crontab</span></code></a></li>
|
|
169
|
+<li><a class="reference internal" href="#task.delayed" title="task.delayed"><code class="xref py py-class docutils literal notranslate"><span class="pre">task.delayed</span></code></a></li>
|
|
170
|
+<li><a class="reference internal" href="#task.periodic" title="task.periodic"><code class="xref py py-class docutils literal notranslate"><span class="pre">task.periodic</span></code></a></li>
|
|
171
|
+<li><a class="reference internal" href="#task.queue" title="task.queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">task.queue</span></code></a></li>
|
|
172
|
+<li><a class="reference internal" href="#task.threaded_queue" title="task.threaded_queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">task.threaded_queue</span></code></a></li>
|
|
173
|
+</ul>
|
|
174
|
+<p><strong>Unittest:</strong></p>
|
|
175
|
+<blockquote>
|
|
176
|
+<div>See also the <a class="reference download internal" download="" href="_downloads/89eb74c94e7790229553fd55e6dfe3a3/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
|
|
177
|
+<p><strong>Module Documentation:</strong></p>
|
|
178
|
+<dl class="class">
|
|
179
|
+<dt id="task.crontab">
|
|
180
|
+<em class="property">class </em><code class="descclassname">task.</code><code class="descname">crontab</code><span class="sig-paren">(</span><em>accuracy=30</em><span class="sig-paren">)</span><a class="headerlink" href="#task.crontab" title="Permalink to this definition">¶</a></dt>
|
|
181
|
+<dd><p>Class to execute a callback at the specified time conditions. See also parent <a class="reference internal" href="#task.periodic" title="task.periodic"><code class="xref py py-class docutils literal notranslate"><span class="pre">periodic</span></code></a>.</p>
|
|
182
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
183
|
+<col class="field-name" />
|
|
184
|
+<col class="field-body" />
|
|
185
|
+<tbody valign="top">
|
|
186
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>accuracy</strong> (<em>float</em>) – Repeat time in seconds for background task checking event triggering. This time is the maximum delay between specified time condition and the execution.</td>
|
|
187
|
+</tr>
|
|
188
|
+</tbody>
|
|
189
|
+</table>
|
|
190
|
+<p><strong>Example:</strong></p>
|
|
191
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
192
|
+<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
193
|
+
|
|
194
|
+<span class="kn">import</span> <span class="nn">sys</span>
|
|
195
|
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
196
|
+<span class="kn">import</span> <span class="nn">task</span>
|
|
197
|
+<span class="kn">import</span> <span class="nn">time</span>
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+<span class="k">def</span> <span class="nf">print_localtime</span><span class="p">(</span><span class="n">cj</span><span class="p">):</span>
|
|
201
|
+ <span class="nb">print</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">localtime</span><span class="p">())</span>
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+<span class="n">ct</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">crontab</span><span class="p">(</span><span class="n">accuracy</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
|
|
205
|
+<span class="n">minute</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">'%M'</span><span class="p">))</span>
|
|
206
|
+<span class="n">ct</span><span class="o">.</span><span class="n">add_cronjob</span><span class="p">([</span><span class="n">minute</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">minute</span> <span class="o">+</span> <span class="mi">3</span><span class="p">],</span> <span class="n">task</span><span class="o">.</span><span class="n">crontab</span><span class="o">.</span><span class="n">ANY</span><span class="p">,</span> <span class="n">task</span><span class="o">.</span><span class="n">crontab</span><span class="o">.</span><span class="n">ANY</span><span class="p">,</span> <span class="n">task</span><span class="o">.</span><span class="n">crontab</span><span class="o">.</span><span class="n">ANY</span><span class="p">,</span> <span class="n">task</span><span class="o">.</span><span class="n">crontab</span><span class="o">.</span><span class="n">ANY</span><span class="p">,</span> <span class="n">print_localtime</span><span class="p">)</span>
|
|
207
|
+<span class="nb">print</span><span class="p">(</span><span class="s1">'Cronjob added for Minute: </span><span class="si">%02d</span><span class="s1">, </span><span class="si">%02d</span><span class="se">\n</span><span class="s1">--------------------------------</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">minute</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">minute</span> <span class="o">+</span> <span class="mi">3</span><span class="p">))</span>
|
|
208
|
+<span class="n">ct</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
|
|
209
|
+<span class="k">try</span><span class="p">:</span>
|
|
210
|
+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">195</span><span class="p">)</span>
|
|
211
|
+ <span class="n">ct</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
212
|
+ <span class="n">ct</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|
213
|
+<span class="k">finally</span><span class="p">:</span>
|
|
214
|
+ <span class="n">ct</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
215
|
+</pre></div>
|
|
216
|
+</div>
|
|
217
|
+<p>Will result to the following output:</p>
|
|
218
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Cronjob</span> <span class="n">added</span> <span class="k">for</span> <span class="n">Minute</span><span class="p">:</span> <span class="mi">45</span><span class="p">,</span> <span class="mi">47</span>
|
|
219
|
+<span class="o">--------------------------------</span>
|
|
220
|
+
|
|
221
|
+<span class="n">time</span><span class="o">.</span><span class="n">struct_time</span><span class="p">(</span><span class="n">tm_year</span><span class="o">=</span><span class="mi">2021</span><span class="p">,</span> <span class="n">tm_mon</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">tm_mday</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">tm_hour</span><span class="o">=</span><span class="mi">17</span><span class="p">,</span> <span class="n">tm_min</span><span class="o">=</span><span class="mi">45</span><span class="p">,</span> <span class="n">tm_sec</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">tm_wday</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">tm_yday</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">tm_isdst</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
|
|
222
|
+<span class="n">time</span><span class="o">.</span><span class="n">struct_time</span><span class="p">(</span><span class="n">tm_year</span><span class="o">=</span><span class="mi">2021</span><span class="p">,</span> <span class="n">tm_mon</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">tm_mday</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">tm_hour</span><span class="o">=</span><span class="mi">17</span><span class="p">,</span> <span class="n">tm_min</span><span class="o">=</span><span class="mi">47</span><span class="p">,</span> <span class="n">tm_sec</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">tm_wday</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">tm_yday</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">tm_isdst</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
|
|
223
|
+</pre></div>
|
|
224
|
+</div>
|
|
225
|
+<dl class="attribute">
|
|
226
|
+<dt id="task.crontab.ANY">
|
|
227
|
+<code class="descname">ANY</code><em class="property"> = '*'</em><a class="headerlink" href="#task.crontab.ANY" title="Permalink to this definition">¶</a></dt>
|
|
228
|
+<dd><p>Constant for matching every condition.</p>
|
|
229
|
+</dd></dl>
|
|
230
|
+
|
|
231
|
+<dl class="method">
|
|
232
|
+<dt id="task.crontab.add_cronjob">
|
|
233
|
+<code class="descname">add_cronjob</code><span class="sig-paren">(</span><em>minute</em>, <em>hour</em>, <em>day_of_month</em>, <em>month</em>, <em>day_of_week</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#task.crontab.add_cronjob" title="Permalink to this definition">¶</a></dt>
|
|
234
|
+<dd><p>This Method adds a cronjob to be executed.</p>
|
|
235
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
236
|
+<col class="field-name" />
|
|
237
|
+<col class="field-body" />
|
|
238
|
+<tbody valign="top">
|
|
239
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
240
|
+<li><strong>minute</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Minute for execution. Either 0…59, [0…59, 0…59, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Minute.</li>
|
|
241
|
+<li><strong>hour</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Hour for execution. Either 0…23, [0…23, 0…23, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Hour.</li>
|
|
242
|
+<li><strong>day_of_month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Month for execution. Either 0…31, [0…31, 0…31, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Month.</li>
|
|
243
|
+<li><strong>month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Month for execution. Either 0…12, [0…12, 0…12, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Month.</li>
|
|
244
|
+<li><strong>day_of_week</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Week for execution. Either 0…6, [0…6, 0…6, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Week.</li>
|
|
245
|
+<li><strong>callback</strong> (<em>func</em>) – The callback to be executed. The instance of <a class="reference internal" href="#task.crontab.cronjob" title="task.crontab.cronjob"><code class="xref py py-class docutils literal notranslate"><span class="pre">cronjob</span></code></a> will be given as the first, args and kwargs as the following parameters.</li>
|
|
246
|
+</ul>
|
|
247
|
+</td>
|
|
248
|
+</tr>
|
|
249
|
+</tbody>
|
|
250
|
+</table>
|
|
251
|
+<div class="admonition note">
|
|
252
|
+<p class="first admonition-title">Note</p>
|
|
253
|
+<p class="last">The <code class="docutils literal notranslate"><span class="pre">callback</span></code> will be executed with it’s instance of <a class="reference internal" href="#task.crontab.cronjob" title="task.crontab.cronjob"><code class="xref py py-class docutils literal notranslate"><span class="pre">cronjob</span></code></a> as the first parameter.
|
|
254
|
+The given Arguments (<code class="xref py py-data docutils literal notranslate"><span class="pre">args</span></code>) and keyword Arguments (<code class="xref py py-data docutils literal notranslate"><span class="pre">kwargs</span></code>) will be stored in that object.</p>
|
|
255
|
+</div>
|
|
256
|
+</dd></dl>
|
|
257
|
+
|
|
258
|
+<dl class="class">
|
|
259
|
+<dt id="task.crontab.cronjob">
|
|
260
|
+<em class="property">class </em><code class="descname">cronjob</code><span class="sig-paren">(</span><em>minute</em>, <em>hour</em>, <em>day_of_month</em>, <em>month</em>, <em>day_of_week</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#task.crontab.cronjob" title="Permalink to this definition">¶</a></dt>
|
|
261
|
+<dd><p>Class to handle cronjob parameters and cronjob changes.</p>
|
|
262
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
263
|
+<col class="field-name" />
|
|
264
|
+<col class="field-body" />
|
|
265
|
+<tbody valign="top">
|
|
266
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
267
|
+<li><strong>minute</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Minute for execution. Either 0…59, [0…59, 0…59, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Minute.</li>
|
|
268
|
+<li><strong>hour</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Hour for execution. Either 0…23, [0…23, 0…23, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Hour.</li>
|
|
269
|
+<li><strong>day_of_month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Month for execution. Either 0…31, [0…31, 0…31, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Month.</li>
|
|
270
|
+<li><strong>month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Month for execution. Either 0…12, [0…12, 0…12, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Month.</li>
|
|
271
|
+<li><strong>day_of_week</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Week for execution. Either 0…6, [0…6, 0…6, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Week.</li>
|
|
272
|
+<li><strong>callback</strong> (<em>func</em>) – The callback to be executed. The instance of <code class="xref py py-class docutils literal notranslate"><span class="pre">cronjob</span></code> will be given as the first, args and kwargs as the following parameters.</li>
|
|
273
|
+</ul>
|
|
274
|
+</td>
|
|
275
|
+</tr>
|
|
276
|
+</tbody>
|
|
277
|
+</table>
|
|
278
|
+<div class="admonition note">
|
|
279
|
+<p class="first admonition-title">Note</p>
|
|
280
|
+<p class="last">This class should not be used stand alone. An instance will be created by adding a cronjob by using <a class="reference internal" href="#task.crontab.add_cronjob" title="task.crontab.add_cronjob"><code class="xref py py-func docutils literal notranslate"><span class="pre">crontab.add_cronjob()</span></code></a>.</p>
|
|
281
|
+</div>
|
|
282
|
+<dl class="class">
|
|
283
|
+<dt id="task.crontab.cronjob.all_match">
|
|
284
|
+<em class="property">class </em><code class="descname">all_match</code><a class="headerlink" href="#task.crontab.cronjob.all_match" title="Permalink to this definition">¶</a></dt>
|
|
285
|
+<dd><p>Universal set - match everything</p>
|
|
286
|
+</dd></dl>
|
|
287
|
+
|
|
288
|
+<dl class="method">
|
|
289
|
+<dt id="task.crontab.cronjob.cron_execution">
|
|
290
|
+<code class="descname">cron_execution</code><span class="sig-paren">(</span><em>tm</em><span class="sig-paren">)</span><a class="headerlink" href="#task.crontab.cronjob.cron_execution" title="Permalink to this definition">¶</a></dt>
|
|
291
|
+<dd><p>This Methods executes the Cron-Callback, if a execution is needed for the given time (depending on the parameters on initialisation)</p>
|
|
292
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
293
|
+<col class="field-name" />
|
|
294
|
+<col class="field-body" />
|
|
295
|
+<tbody valign="top">
|
|
296
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>tm</strong> (<em>int</em>) – (Current) Time Value to be checked. The time needs to be given in seconds since 1970 (e.g. generated by int(time.time())).</td>
|
|
297
|
+</tr>
|
|
298
|
+</tbody>
|
|
299
|
+</table>
|
|
300
|
+</dd></dl>
|
|
301
|
+
|
|
302
|
+<dl class="method">
|
|
303
|
+<dt id="task.crontab.cronjob.set_trigger_conditions">
|
|
304
|
+<code class="descname">set_trigger_conditions</code><span class="sig-paren">(</span><em>minute=None</em>, <em>hour=None</em>, <em>day_of_month=None</em>, <em>month=None</em>, <em>day_of_week=None</em><span class="sig-paren">)</span><a class="headerlink" href="#task.crontab.cronjob.set_trigger_conditions" title="Permalink to this definition">¶</a></dt>
|
|
305
|
+<dd><p>This Method changes the execution parameters.</p>
|
|
306
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
307
|
+<col class="field-name" />
|
|
308
|
+<col class="field-body" />
|
|
309
|
+<tbody valign="top">
|
|
310
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
311
|
+<li><strong>minute</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Minute for execution. Either 0…59, [0…59, 0…59, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Minute.</li>
|
|
312
|
+<li><strong>hour</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Hour for execution. Either 0…23, [0…23, 0…23, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Hour.</li>
|
|
313
|
+<li><strong>day_of_month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Month for execution. Either 0…31, [0…31, 0…31, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Month.</li>
|
|
314
|
+<li><strong>month</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Month for execution. Either 0…12, [0…12, 0…12, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Month.</li>
|
|
315
|
+<li><strong>day_of_week</strong> (<em>int</em><em>, </em><em>list</em><em>, </em><em>str</em>) – Day of Week for execution. Either 0…6, [0…6, 0…6, …] or <a class="reference internal" href="#task.crontab.ANY" title="task.crontab.ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">crontab.ANY</span></code></a> for every Day of Week.</li>
|
|
316
|
+</ul>
|
|
317
|
+</td>
|
|
318
|
+</tr>
|
|
319
|
+</tbody>
|
|
320
|
+</table>
|
|
321
|
+</dd></dl>
|
|
322
|
+
|
|
323
|
+</dd></dl>
|
|
324
|
+
|
|
325
|
+</dd></dl>
|
|
326
|
+
|
|
327
|
+<dl class="class">
|
|
328
|
+<dt id="task.delayed">
|
|
329
|
+<em class="property">class </em><code class="descclassname">task.</code><code class="descname">delayed</code><span class="sig-paren">(</span><em>cycle_time</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#task.delayed" title="Permalink to this definition">¶</a></dt>
|
|
330
|
+<dd><p>Class to execute a callback a given time in the future. See also parent <a class="reference internal" href="#task.periodic" title="task.periodic"><code class="xref py py-class docutils literal notranslate"><span class="pre">periodic</span></code></a>.</p>
|
|
331
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
332
|
+<col class="field-name" />
|
|
333
|
+<col class="field-body" />
|
|
334
|
+<tbody valign="top">
|
|
335
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
336
|
+<li><strong>time</strong> (<em>float</em>) – Delay time for execution of the given callback</li>
|
|
337
|
+<li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
|
|
338
|
+<li><strong>args</strong> (<em>args</em>) – Arguments to be given to callback</li>
|
|
339
|
+<li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
|
|
340
|
+</ul>
|
|
341
|
+</td>
|
|
342
|
+</tr>
|
|
343
|
+</tbody>
|
|
344
|
+</table>
|
|
345
|
+<p><strong>Example:</strong></p>
|
|
346
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
347
|
+<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
348
|
+
|
|
349
|
+<span class="kn">import</span> <span class="nn">sys</span>
|
|
350
|
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
351
|
+<span class="kn">import</span> <span class="nn">task</span>
|
|
352
|
+<span class="kn">import</span> <span class="nn">time</span>
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+<span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
|
|
356
|
+ <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">()</span> <span class="o">+</span> <span class="s1">': '</span> <span class="o">+</span> <span class="n">txt</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+<span class="nb">print</span><span class="p">(</span><span class="s2">"task.delayed example:</span><span class="se">\n</span><span class="s2">---------------------"</span><span class="p">)</span>
|
|
360
|
+<span class="n">dt</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">delayed</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">time_print</span><span class="p">,</span> <span class="s2">"A delayed hello!"</span><span class="p">)</span>
|
|
361
|
+<span class="n">dt</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
|
|
362
|
+<span class="k">try</span><span class="p">:</span>
|
|
363
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
|
|
364
|
+ <span class="n">dt</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|
365
|
+<span class="k">finally</span><span class="p">:</span>
|
|
366
|
+ <span class="n">dt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
367
|
+</pre></div>
|
|
368
|
+</div>
|
|
369
|
+<p>Will result to the following output:</p>
|
|
370
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.delayed example:
|
|
371
|
+---------------------
|
|
372
|
+Thu Jan 7 17:18:01 2021: starting...
|
|
373
|
+Thu Jan 7 17:18:06 2021: A delayed hello!
|
|
374
|
+</pre></div>
|
|
375
|
+</div>
|
|
376
|
+<dl class="method">
|
|
377
|
+<dt id="task.delayed.run">
|
|
378
|
+<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.delayed.run" title="Permalink to this definition">¶</a></dt>
|
|
379
|
+<dd><p>This starts the timer for the delayed execution.</p>
|
|
380
|
+</dd></dl>
|
|
381
|
+
|
|
382
|
+</dd></dl>
|
|
383
|
+
|
|
384
|
+<dl class="class">
|
|
385
|
+<dt id="task.periodic">
|
|
386
|
+<em class="property">class </em><code class="descclassname">task.</code><code class="descname">periodic</code><span class="sig-paren">(</span><em>cycle_time</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#task.periodic" title="Permalink to this definition">¶</a></dt>
|
|
387
|
+<dd><p>Class to execute a callback cyclicly.</p>
|
|
388
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
389
|
+<col class="field-name" />
|
|
390
|
+<col class="field-body" />
|
|
391
|
+<tbody valign="top">
|
|
392
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
393
|
+<li><strong>cycle_time</strong> (<em>float</em>) – Cycle time in seconds – callback will be executed every <em>cycle_time</em> seconds</li>
|
|
394
|
+<li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
|
|
395
|
+<li><strong>args</strong> (<em>args</em>) – Arguments to be given to the callback</li>
|
|
396
|
+<li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
|
|
397
|
+</ul>
|
|
398
|
+</td>
|
|
399
|
+</tr>
|
|
400
|
+</tbody>
|
|
401
|
+</table>
|
|
402
|
+<div class="admonition note">
|
|
403
|
+<p class="first admonition-title">Note</p>
|
|
404
|
+<p class="last">The Callback will get this instance as first argument, followed by <code class="xref py py-data docutils literal notranslate"><span class="pre">args</span></code> und <code class="xref py py-data docutils literal notranslate"><span class="pre">kwargs</span></code>.</p>
|
|
405
|
+</div>
|
|
406
|
+<p><strong>Example:</strong></p>
|
|
407
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
408
|
+<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
409
|
+
|
|
410
|
+<span class="kn">import</span> <span class="nn">sys</span>
|
|
411
|
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
412
|
+<span class="kn">import</span> <span class="nn">task</span>
|
|
413
|
+<span class="kn">import</span> <span class="nn">time</span>
|
|
414
|
+
|
|
415
|
+<span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+<span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
|
|
419
|
+ <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">()</span> <span class="o">+</span> <span class="s1">': '</span> <span class="o">+</span> <span class="n">txt</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+<span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">rt</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
|
423
|
+ <span class="k">global</span> <span class="n">task_num</span>
|
|
424
|
+ <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
|
|
425
|
+ <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
|
|
426
|
+ <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
427
|
+ <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
|
|
428
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Hello </span><span class="si">%s</span><span class="s2">!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
|
|
429
|
+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span>
|
|
430
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Ende!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">))</span>
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+<span class="nb">print</span><span class="p">(</span><span class="s2">"task.periodic example:</span><span class="se">\n</span><span class="s2">----------------------"</span><span class="p">)</span>
|
|
434
|
+<span class="n">pt</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">periodic</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from periodic example"</span><span class="p">)</span>
|
|
435
|
+<span class="n">pt</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
|
|
436
|
+<span class="k">try</span><span class="p">:</span>
|
|
437
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
|
|
438
|
+ <span class="n">pt</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|
439
|
+<span class="k">finally</span><span class="p">:</span>
|
|
440
|
+ <span class="n">pt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
441
|
+</pre></div>
|
|
442
|
+</div>
|
|
443
|
+<p>Will result to the following output:</p>
|
|
444
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.periodic example:
|
|
445
|
+----------------------
|
|
446
|
+Thu Jan 7 17:21:26 2021: starting...
|
|
447
|
+Thu Jan 7 17:21:26 2021: (Task 1) Hello from periodic example!
|
|
448
|
+Thu Jan 7 17:21:28 2021: (Task 2) Hello from periodic example!
|
|
449
|
+Thu Jan 7 17:21:30 2021: (Task 1) Ende!
|
|
450
|
+Thu Jan 7 17:21:30 2021: (Task 3) Hello from periodic example!
|
|
451
|
+Thu Jan 7 17:21:32 2021: (Task 2) Ende!
|
|
452
|
+Thu Jan 7 17:21:32 2021: (Task 4) Hello from periodic example!
|
|
453
|
+Thu Jan 7 17:21:34 2021: (Task 3) Ende!
|
|
454
|
+Thu Jan 7 17:21:34 2021: (Task 5) Hello from periodic example!
|
|
455
|
+Thu Jan 7 17:21:36 2021: (Task 4) Ende!
|
|
456
|
+Thu Jan 7 17:21:38 2021: (Task 5) Ende!
|
|
457
|
+</pre></div>
|
|
458
|
+</div>
|
|
459
|
+<dl class="method">
|
|
460
|
+<dt id="task.periodic.join">
|
|
461
|
+<code class="descname">join</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.periodic.join" title="Permalink to this definition">¶</a></dt>
|
|
462
|
+<dd><p>This blocks till the cyclic task is terminated.</p>
|
|
463
|
+<div class="admonition note">
|
|
464
|
+<p class="first admonition-title">Note</p>
|
|
465
|
+<p class="last">Using join means that somewhere has to be a condition calling <a class="reference internal" href="#task.periodic.stop" title="task.periodic.stop"><code class="xref py py-func docutils literal notranslate"><span class="pre">stop()</span></code></a> to terminate. Otherwise <code class="xref py py-func docutils literal notranslate"><span class="pre">task.join()</span></code> will never return.</p>
|
|
466
|
+</div>
|
|
467
|
+</dd></dl>
|
|
468
|
+
|
|
469
|
+<dl class="method">
|
|
470
|
+<dt id="task.periodic.run">
|
|
471
|
+<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.periodic.run" title="Permalink to this definition">¶</a></dt>
|
|
472
|
+<dd><p>This starts the cyclic execution of the given callback.</p>
|
|
473
|
+</dd></dl>
|
|
474
|
+
|
|
475
|
+<dl class="method">
|
|
476
|
+<dt id="task.periodic.stop">
|
|
477
|
+<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.periodic.stop" title="Permalink to this definition">¶</a></dt>
|
|
478
|
+<dd><p>This stops the execution of any further task.</p>
|
|
479
|
+</dd></dl>
|
|
480
|
+
|
|
481
|
+</dd></dl>
|
|
482
|
+
|
|
483
|
+<dl class="class">
|
|
484
|
+<dt id="task.queue">
|
|
485
|
+<em class="property">class </em><code class="descclassname">task.</code><code class="descname">queue</code><span class="sig-paren">(</span><em>expire=True</em><span class="sig-paren">)</span><a class="headerlink" href="#task.queue" title="Permalink to this definition">¶</a></dt>
|
|
486
|
+<dd><p>Class to execute queued callbacks.</p>
|
|
487
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
488
|
+<col class="field-name" />
|
|
489
|
+<col class="field-body" />
|
|
490
|
+<tbody valign="top">
|
|
491
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>expire</strong> (<em>bool</em>) – The default value for expire. See also <a class="reference internal" href="#task.queue.expire" title="task.queue.expire"><code class="xref py py-func docutils literal notranslate"><span class="pre">expire()</span></code></a>.</td>
|
|
492
|
+</tr>
|
|
493
|
+</tbody>
|
|
494
|
+</table>
|
|
495
|
+<p><strong>Example:</strong></p>
|
|
496
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
497
|
+<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
498
|
+
|
|
499
|
+<span class="kn">import</span> <span class="nn">sys</span>
|
|
500
|
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
501
|
+<span class="kn">import</span> <span class="nn">task</span>
|
|
502
|
+<span class="kn">import</span> <span class="nn">time</span>
|
|
503
|
+
|
|
504
|
+<span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+<span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
|
|
508
|
+ <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">()</span> <span class="o">+</span> <span class="s1">': '</span> <span class="o">+</span> <span class="n">txt</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+<span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">rt</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
|
512
|
+ <span class="k">global</span> <span class="n">task_num</span>
|
|
513
|
+ <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
|
|
514
|
+ <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
|
|
515
|
+ <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
516
|
+ <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
|
|
517
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Hello </span><span class="si">%s</span><span class="s2">!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
|
|
518
|
+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span>
|
|
519
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Ende!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">))</span>
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+<span class="nb">print</span><span class="p">(</span><span class="s2">"task.queue example:</span><span class="se">\n</span><span class="s2">----------------------"</span><span class="p">)</span>
|
|
523
|
+<span class="n">q</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">queue</span><span class="p">()</span>
|
|
524
|
+<span class="n">q</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (5)"</span><span class="p">)</span>
|
|
525
|
+<span class="n">q</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (6)"</span><span class="p">)</span>
|
|
526
|
+<span class="n">q</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (4)"</span><span class="p">)</span>
|
|
527
|
+<span class="n">q</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
|
|
528
|
+</pre></div>
|
|
529
|
+</div>
|
|
530
|
+<p>Will result to the following output:</p>
|
|
531
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.queue example:
|
|
532
|
+----------------------
|
|
533
|
+Thu Jan 7 17:30:54 2021: (Task 1) Hello from queue example (4)!
|
|
534
|
+Thu Jan 7 17:30:58 2021: (Task 1) Ende!
|
|
535
|
+Thu Jan 7 17:30:58 2021: (Task 2) Hello from queue example (5)!
|
|
536
|
+Thu Jan 7 17:31:02 2021: (Task 2) Ende!
|
|
537
|
+Thu Jan 7 17:31:02 2021: (Task 3) Hello from queue example (6)!
|
|
538
|
+Thu Jan 7 17:31:06 2021: (Task 3) Ende!
|
|
539
|
+</pre></div>
|
|
540
|
+</div>
|
|
541
|
+<dl class="method">
|
|
542
|
+<dt id="task.queue.clean_queue">
|
|
543
|
+<code class="descname">clean_queue</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.queue.clean_queue" title="Permalink to this definition">¶</a></dt>
|
|
544
|
+<dd><p>This Methods removes all jobs from the queue.</p>
|
|
545
|
+<div class="admonition note">
|
|
546
|
+<p class="first admonition-title">Note</p>
|
|
547
|
+<p class="last">Be aware that already running jobs will not be terminated.</p>
|
|
548
|
+</div>
|
|
549
|
+</dd></dl>
|
|
550
|
+
|
|
551
|
+<dl class="method">
|
|
552
|
+<dt id="task.queue.enqueue">
|
|
553
|
+<code class="descname">enqueue</code><span class="sig-paren">(</span><em>priority</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#task.queue.enqueue" title="Permalink to this definition">¶</a></dt>
|
|
554
|
+<dd><p>This enqueues a given callback.</p>
|
|
555
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
556
|
+<col class="field-name" />
|
|
557
|
+<col class="field-body" />
|
|
558
|
+<tbody valign="top">
|
|
559
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
560
|
+<li><strong>priority</strong> (<em>number</em>) – The priority indication number of this task. The lowest value will be queued first.</li>
|
|
561
|
+<li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
|
|
562
|
+<li><strong>args</strong> (<em>args</em>) – Arguments to be given to callback</li>
|
|
563
|
+<li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
|
|
564
|
+</ul>
|
|
565
|
+</td>
|
|
566
|
+</tr>
|
|
567
|
+</tbody>
|
|
568
|
+</table>
|
|
569
|
+<div class="admonition note">
|
|
570
|
+<p class="first admonition-title">Note</p>
|
|
571
|
+<p class="last">Callback will get this instance as first argument, followed by <code class="xref py py-data docutils literal notranslate"><span class="pre">args</span></code> und <code class="xref py py-data docutils literal notranslate"><span class="pre">kwargs</span></code>.</p>
|
|
572
|
+</div>
|
|
573
|
+</dd></dl>
|
|
574
|
+
|
|
575
|
+<dl class="method">
|
|
576
|
+<dt id="task.queue.expire">
|
|
577
|
+<code class="descname">expire</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.queue.expire" title="Permalink to this definition">¶</a></dt>
|
|
578
|
+<dd><p>This sets the expire flag. That means that the process will stop after queue gets empty.</p>
|
|
579
|
+</dd></dl>
|
|
580
|
+
|
|
581
|
+<dl class="method">
|
|
582
|
+<dt id="task.queue.run">
|
|
583
|
+<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.queue.run" title="Permalink to this definition">¶</a></dt>
|
|
584
|
+<dd><p>This starts the execution of the queued callbacks.</p>
|
|
585
|
+</dd></dl>
|
|
586
|
+
|
|
587
|
+<dl class="method">
|
|
588
|
+<dt id="task.queue.stop">
|
|
589
|
+<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.queue.stop" title="Permalink to this definition">¶</a></dt>
|
|
590
|
+<dd><p>This sets the stop flag. That means that the process will stop after finishing the active task.</p>
|
|
591
|
+</dd></dl>
|
|
592
|
+
|
|
593
|
+</dd></dl>
|
|
594
|
+
|
|
595
|
+<dl class="class">
|
|
596
|
+<dt id="task.threaded_queue">
|
|
597
|
+<em class="property">class </em><code class="descclassname">task.</code><code class="descname">threaded_queue</code><span class="sig-paren">(</span><em>expire=False</em><span class="sig-paren">)</span><a class="headerlink" href="#task.threaded_queue" title="Permalink to this definition">¶</a></dt>
|
|
598
|
+<dd><p>Class to execute queued callbacks in a background thread (See also parent <a class="reference internal" href="#task.queue" title="task.queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">queue</span></code></a>).</p>
|
|
599
|
+<table class="docutils field-list" frame="void" rules="none">
|
|
600
|
+<col class="field-name" />
|
|
601
|
+<col class="field-body" />
|
|
602
|
+<tbody valign="top">
|
|
603
|
+<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>expire</strong> (<em>bool</em>) – The default value for expire. See also <a class="reference internal" href="#task.queue.expire" title="task.queue.expire"><code class="xref py py-func docutils literal notranslate"><span class="pre">queue.expire()</span></code></a>.</td>
|
|
604
|
+</tr>
|
|
605
|
+</tbody>
|
|
606
|
+</table>
|
|
607
|
+<p><strong>Example:</strong></p>
|
|
608
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
609
|
+<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
610
|
+
|
|
611
|
+<span class="kn">import</span> <span class="nn">sys</span>
|
|
612
|
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
613
|
+<span class="kn">import</span> <span class="nn">task</span>
|
|
614
|
+<span class="kn">import</span> <span class="nn">time</span>
|
|
615
|
+
|
|
616
|
+<span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+<span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
|
|
620
|
+ <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">asctime</span><span class="p">()</span> <span class="o">+</span> <span class="s1">': '</span> <span class="o">+</span> <span class="n">txt</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+<span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">rt</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
|
624
|
+ <span class="k">global</span> <span class="n">task_num</span>
|
|
625
|
+ <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
|
|
626
|
+ <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
|
|
627
|
+ <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
628
|
+ <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
|
|
629
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Hello </span><span class="si">%s</span><span class="s2">!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span>
|
|
630
|
+ <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span>
|
|
631
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"(Task </span><span class="si">%d</span><span class="s2">) Ende!"</span> <span class="o">%</span> <span class="p">(</span><span class="n">tn</span><span class="p">))</span>
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+<span class="nb">print</span><span class="p">(</span><span class="s2">"task.threaded_queue example:</span><span class="se">\n</span><span class="s2">-------------------------------"</span><span class="p">)</span>
|
|
635
|
+<span class="n">tq</span> <span class="o">=</span> <span class="n">task</span><span class="o">.</span><span class="n">threaded_queue</span><span class="p">()</span>
|
|
636
|
+<span class="n">tq</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (5)"</span><span class="p">)</span>
|
|
637
|
+<span class="n">tq</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (6)"</span><span class="p">)</span>
|
|
638
|
+<span class="n">tq</span><span class="o">.</span><span class="n">enqueue</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="n">hello</span><span class="p">,</span> <span class="s2">"from queue example (4)"</span><span class="p">)</span>
|
|
639
|
+<span class="n">tq</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
|
|
640
|
+<span class="k">try</span><span class="p">:</span>
|
|
641
|
+ <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
|
|
642
|
+ <span class="n">tq</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|
643
|
+<span class="k">finally</span><span class="p">:</span>
|
|
644
|
+ <span class="n">tq</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
|
|
645
|
+</pre></div>
|
|
646
|
+</div>
|
|
647
|
+<p>Will result to the following output:</p>
|
|
648
|
+<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.threaded_queue example:
|
|
649
|
+-------------------------------
|
|
650
|
+Thu Jan 7 17:33:50 2021: (Task 1) Hello from queue example (4)!
|
|
651
|
+Thu Jan 7 17:33:50 2021: starting...
|
|
652
|
+Thu Jan 7 17:33:54 2021: (Task 1) Ende!
|
|
653
|
+Thu Jan 7 17:33:54 2021: (Task 2) Hello from queue example (5)!
|
|
654
|
+Thu Jan 7 17:33:58 2021: (Task 2) Ende!
|
|
655
|
+Thu Jan 7 17:33:58 2021: (Task 3) Hello from queue example (6)!
|
|
656
|
+Thu Jan 7 17:34:01 2021: (Task 3) Ende!
|
|
657
|
+</pre></div>
|
|
658
|
+</div>
|
|
659
|
+<dl class="method">
|
|
660
|
+<dt id="task.threaded_queue.join">
|
|
661
|
+<code class="descname">join</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.threaded_queue.join" title="Permalink to this definition">¶</a></dt>
|
|
662
|
+<dd><p>This blocks till the queue is empty.</p>
|
|
663
|
+<div class="admonition note">
|
|
664
|
+<p class="first admonition-title">Note</p>
|
|
665
|
+<p class="last">If the queue does not run dry, join will block till the end of the days.</p>
|
|
666
|
+</div>
|
|
667
|
+</dd></dl>
|
|
668
|
+
|
|
669
|
+<dl class="method">
|
|
670
|
+<dt id="task.threaded_queue.run">
|
|
671
|
+<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.threaded_queue.run" title="Permalink to this definition">¶</a></dt>
|
|
672
|
+<dd><p>This starts the execution of the queued callbacks.</p>
|
|
673
|
+</dd></dl>
|
|
674
|
+
|
|
675
|
+<dl class="method">
|
|
676
|
+<dt id="task.threaded_queue.stop">
|
|
677
|
+<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#task.threaded_queue.stop" title="Permalink to this definition">¶</a></dt>
|
|
678
|
+<dd><p>This sets the stop flag. That means that the process will stop after finishing the active task.</p>
|
|
679
|
+</dd></dl>
|
|
680
|
+
|
|
681
|
+</dd></dl>
|
|
682
|
+
|
|
683
|
+</div>
|
|
684
|
+<div class="toctree-wrapper compound">
|
|
685
|
+</div>
|
|
686
|
+</div>
|
|
687
|
+<div class="section" id="indices-and-tables">
|
|
688
|
+<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
|
|
689
|
+<ul class="simple">
|
|
690
|
+<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
|
|
691
|
+<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
|
|
692
|
+<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
|
|
693
|
+</ul>
|
|
694
|
+</div>
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+ </div>
|
|
698
|
+
|
|
699
|
+ </div>
|
|
700
|
+ <footer>
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+ <hr/>
|
|
704
|
+
|
|
705
|
+ <div role="contentinfo">
|
|
706
|
+ <p>
|
|
707
|
+
|
|
708
|
+ © Copyright 2021, Dirk Alders
|
|
709
|
+
|
|
710
|
+ </p>
|
|
711
|
+ </div>
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+ Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
|
|
716
|
+
|
|
717
|
+ <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
|
|
718
|
+
|
|
719
|
+ provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
720
|
+
|
|
721
|
+</footer>
|
|
722
|
+
|
|
723
|
+ </div>
|
|
724
|
+ </div>
|
|
725
|
+
|
|
726
|
+ </section>
|
|
727
|
+
|
|
728
|
+ </div>
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+ <script type="text/javascript">
|
|
732
|
+ jQuery(function () {
|
|
733
|
+ SphinxRtdTheme.Navigation.enable(true);
|
|
734
|
+ });
|
|
735
|
+ </script>
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+</body>
|
|
743
|
+</html>
|