123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
-
-
- <!DOCTYPE html>
- <html class="writer-html4" lang="en" >
- <head>
- <meta charset="utf-8">
-
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
- <title>Welcome to task’s documentation! — task documentation</title>
-
-
-
- <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
-
-
-
-
-
-
-
- <!--[if lt IE 9]>
- <script src="_static/js/html5shiv.min.js"></script>
- <![endif]-->
-
-
- <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
- <script type="text/javascript" src="_static/jquery.js"></script>
- <script type="text/javascript" src="_static/underscore.js"></script>
- <script type="text/javascript" src="_static/doctools.js"></script>
- <script type="text/javascript" src="_static/language_data.js"></script>
-
- <script type="text/javascript" src="_static/js/theme.js"></script>
-
-
- <link rel="index" title="Index" href="genindex.html" />
- <link rel="search" title="Search" href="search.html" />
- </head>
-
- <body class="wy-body-for-nav">
-
-
- <div class="wy-grid-for-nav">
-
- <nav data-toggle="wy-nav-shift" class="wy-nav-side">
- <div class="wy-side-scroll">
- <div class="wy-side-nav-search" >
-
-
-
- <a href="#" class="icon icon-home" alt="Documentation Home"> task
-
-
-
- </a>
-
-
-
-
-
-
-
- <div role="search">
- <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
- <input type="text" name="q" placeholder="Search docs" />
- <input type="hidden" name="check_keywords" value="yes" />
- <input type="hidden" name="area" value="default" />
- </form>
- </div>
-
-
- </div>
-
-
- <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
-
-
-
-
-
-
- <!-- Local TOC -->
- <div class="local-toc"><ul>
- <li><a class="reference internal" href="#">Welcome to task’s documentation!</a><ul>
- <li><a class="reference internal" href="#task-task-module">task (Task Module)</a></li>
- </ul>
- </li>
- <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
- </ul>
- </div>
-
-
- </div>
-
- </div>
- </nav>
-
- <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
-
-
- <nav class="wy-nav-top" aria-label="top navigation">
-
- <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
- <a href="#">task</a>
-
- </nav>
-
-
- <div class="wy-nav-content">
-
- <div class="rst-content">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <div role="navigation" aria-label="breadcrumbs navigation">
-
- <ul class="wy-breadcrumbs">
-
- <li><a href="#" class="icon icon-home"></a> »</li>
-
- <li>Welcome to task’s documentation!</li>
-
-
- <li class="wy-breadcrumbs-aside">
-
-
- <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
-
-
- </li>
-
- </ul>
-
-
- <hr/>
- </div>
- <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
- <div itemprop="articleBody">
-
- <div class="section" id="module-task">
- <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>
- <div class="section" id="task-task-module">
- <h2>task (Task Module)<a class="headerlink" href="#task-task-module" title="Permalink to this headline">¶</a></h2>
- <p><strong>Author:</strong></p>
- <ul class="simple">
- <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>
- </ul>
- <p><strong>Description:</strong></p>
- <blockquote>
- <div>This Module supports helpfull classes for queues, tasks, …</div></blockquote>
- <p><strong>Submodules:</strong></p>
- <ul class="simple">
- <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>
- <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>
- <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>
- <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>
- <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>
- </ul>
- <p><strong>Unittest:</strong></p>
- <blockquote>
- <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>
- <p><strong>Module Documentation:</strong></p>
- <dl class="class">
- <dt id="task.crontab">
- <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>
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <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>
- </tr>
- </tbody>
- </table>
- <p><strong>Example:</strong></p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
- <span class="c1"># -*- coding: UTF-8 -*-</span>
-
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <span class="kn">import</span> <span class="nn">task</span>
- <span class="kn">import</span> <span class="nn">time</span>
-
-
- <span class="k">def</span> <span class="nf">print_localtime</span><span class="p">(</span><span class="n">cj</span><span class="p">):</span>
- <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>
-
-
- <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>
- <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>
- <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>
- <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>
- <span class="n">ct</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
- <span class="k">try</span><span class="p">:</span>
- <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>
- <span class="n">ct</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- <span class="n">ct</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
- <span class="k">finally</span><span class="p">:</span>
- <span class="n">ct</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Will result to the following output:</p>
- <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>
- <span class="o">--------------------------------</span>
-
- <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>
- <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>
- </pre></div>
- </div>
- <dl class="attribute">
- <dt id="task.crontab.ANY">
- <code class="descname">ANY</code><em class="property"> = '*'</em><a class="headerlink" href="#task.crontab.ANY" title="Permalink to this definition">¶</a></dt>
- <dd><p>Constant for matching every condition.</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.crontab.add_cronjob">
- <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>
- <dd><p>This Method adds a cronjob to be executed.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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.
- 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>
- </div>
- </dd></dl>
-
- <dl class="class">
- <dt id="task.crontab.cronjob">
- <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>
- <dd><p>Class to handle cronjob parameters and cronjob changes.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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>
- </div>
- <dl class="class">
- <dt id="task.crontab.cronjob.all_match">
- <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>
- <dd><p>Universal set - match everything</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.crontab.cronjob.cron_execution">
- <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>
- <dd><p>This Methods executes the Cron-Callback, if a execution is needed for the given time (depending on the parameters on initialisation)</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <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>
- </tr>
- </tbody>
- </table>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.crontab.cronjob.set_trigger_conditions">
- <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>
- <dd><p>This Method changes the execution parameters.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <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>
- <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>
- <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>
- <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>
- <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>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- </dd></dl>
-
- </dd></dl>
-
- </dd></dl>
-
- <dl class="class">
- <dt id="task.delayed">
- <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>
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>time</strong> (<em>float</em>) – Delay time for execution of the given callback</li>
- <li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
- <li><strong>args</strong> (<em>args</em>) – Arguments to be given to callback</li>
- <li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <p><strong>Example:</strong></p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
- <span class="c1"># -*- coding: UTF-8 -*-</span>
-
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <span class="kn">import</span> <span class="nn">task</span>
- <span class="kn">import</span> <span class="nn">time</span>
-
-
- <span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
- <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>
-
-
- <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>
- <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>
- <span class="n">dt</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
- <span class="k">try</span><span class="p">:</span>
- <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
- <span class="n">dt</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
- <span class="k">finally</span><span class="p">:</span>
- <span class="n">dt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Will result to the following output:</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.delayed example:
- ---------------------
- Thu Jan 7 17:18:01 2021: starting...
- Thu Jan 7 17:18:06 2021: A delayed hello!
- </pre></div>
- </div>
- <dl class="method">
- <dt id="task.delayed.run">
- <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>
- <dd><p>This starts the timer for the delayed execution.</p>
- </dd></dl>
-
- </dd></dl>
-
- <dl class="class">
- <dt id="task.periodic">
- <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>
- <dd><p>Class to execute a callback cyclicly.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>cycle_time</strong> (<em>float</em>) – Cycle time in seconds – callback will be executed every <em>cycle_time</em> seconds</li>
- <li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
- <li><strong>args</strong> (<em>args</em>) – Arguments to be given to the callback</li>
- <li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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>
- </div>
- <p><strong>Example:</strong></p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
- <span class="c1"># -*- coding: UTF-8 -*-</span>
-
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <span class="kn">import</span> <span class="nn">task</span>
- <span class="kn">import</span> <span class="nn">time</span>
-
- <span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
-
-
- <span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
- <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>
-
-
- <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>
- <span class="k">global</span> <span class="n">task_num</span>
- <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
- <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
- <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
- <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>
- <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>
- <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>
-
-
- <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>
- <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>
- <span class="n">pt</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
- <span class="k">try</span><span class="p">:</span>
- <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
- <span class="n">pt</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
- <span class="k">finally</span><span class="p">:</span>
- <span class="n">pt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Will result to the following output:</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.periodic example:
- ----------------------
- Thu Jan 7 17:21:26 2021: starting...
- Thu Jan 7 17:21:26 2021: (Task 1) Hello from periodic example!
- Thu Jan 7 17:21:28 2021: (Task 2) Hello from periodic example!
- Thu Jan 7 17:21:30 2021: (Task 1) Ende!
- Thu Jan 7 17:21:30 2021: (Task 3) Hello from periodic example!
- Thu Jan 7 17:21:32 2021: (Task 2) Ende!
- Thu Jan 7 17:21:32 2021: (Task 4) Hello from periodic example!
- Thu Jan 7 17:21:34 2021: (Task 3) Ende!
- Thu Jan 7 17:21:34 2021: (Task 5) Hello from periodic example!
- Thu Jan 7 17:21:36 2021: (Task 4) Ende!
- Thu Jan 7 17:21:38 2021: (Task 5) Ende!
- </pre></div>
- </div>
- <dl class="method">
- <dt id="task.periodic.join">
- <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>
- <dd><p>This blocks till the cyclic task is terminated.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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>
- </div>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.periodic.run">
- <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>
- <dd><p>This starts the cyclic execution of the given callback.</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.periodic.stop">
- <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>
- <dd><p>This stops the execution of any further task.</p>
- </dd></dl>
-
- </dd></dl>
-
- <dl class="class">
- <dt id="task.queue">
- <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>
- <dd><p>Class to execute queued callbacks.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <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>
- </tr>
- </tbody>
- </table>
- <p><strong>Example:</strong></p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
- <span class="c1"># -*- coding: UTF-8 -*-</span>
-
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <span class="kn">import</span> <span class="nn">task</span>
- <span class="kn">import</span> <span class="nn">time</span>
-
- <span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
-
-
- <span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
- <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>
-
-
- <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>
- <span class="k">global</span> <span class="n">task_num</span>
- <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
- <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
- <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
- <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>
- <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>
- <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>
-
-
- <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>
- <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>
- <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>
- <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>
- <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>
- <span class="n">q</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Will result to the following output:</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.queue example:
- ----------------------
- Thu Jan 7 17:30:54 2021: (Task 1) Hello from queue example (4)!
- Thu Jan 7 17:30:58 2021: (Task 1) Ende!
- Thu Jan 7 17:30:58 2021: (Task 2) Hello from queue example (5)!
- Thu Jan 7 17:31:02 2021: (Task 2) Ende!
- Thu Jan 7 17:31:02 2021: (Task 3) Hello from queue example (6)!
- Thu Jan 7 17:31:06 2021: (Task 3) Ende!
- </pre></div>
- </div>
- <dl class="method">
- <dt id="task.queue.clean_queue">
- <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>
- <dd><p>This Methods removes all jobs from the queue.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">Be aware that already running jobs will not be terminated.</p>
- </div>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.queue.enqueue">
- <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>
- <dd><p>This enqueues a given callback.</p>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
- <li><strong>priority</strong> (<em>number</em>) – The priority indication number of this task. The lowest value will be queued first.</li>
- <li><strong>callback</strong> (<em>callback</em>) – Callback to be executed</li>
- <li><strong>args</strong> (<em>args</em>) – Arguments to be given to callback</li>
- <li><strong>kwargs</strong> (<em>kwargs</em>) – Keword Arguments to be given to callback</li>
- </ul>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <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>
- </div>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.queue.expire">
- <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>
- <dd><p>This sets the expire flag. That means that the process will stop after queue gets empty.</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.queue.run">
- <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>
- <dd><p>This starts the execution of the queued callbacks.</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.queue.stop">
- <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>
- <dd><p>This sets the stop flag. That means that the process will stop after finishing the active task.</p>
- </dd></dl>
-
- </dd></dl>
-
- <dl class="class">
- <dt id="task.threaded_queue">
- <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>
- <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>
- <table class="docutils field-list" frame="void" rules="none">
- <col class="field-name" />
- <col class="field-body" />
- <tbody valign="top">
- <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>
- </tr>
- </tbody>
- </table>
- <p><strong>Example:</strong></p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
- <span class="c1"># -*- coding: UTF-8 -*-</span>
-
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <span class="kn">import</span> <span class="nn">task</span>
- <span class="kn">import</span> <span class="nn">time</span>
-
- <span class="n">task_num</span> <span class="o">=</span> <span class="mi">0</span>
-
-
- <span class="k">def</span> <span class="nf">time_print</span><span class="p">(</span><span class="n">txt</span><span class="p">):</span>
- <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>
-
-
- <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>
- <span class="k">global</span> <span class="n">task_num</span>
- <span class="n">task_num</span> <span class="o">+=</span> <span class="mi">1</span>
- <span class="k">if</span> <span class="n">task_num</span> <span class="o">>=</span> <span class="mi">5</span><span class="p">:</span>
- <span class="n">rt</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- <span class="n">tn</span> <span class="o">=</span> <span class="n">task_num</span>
- <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>
- <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>
- <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>
-
-
- <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>
- <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>
- <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>
- <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>
- <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>
- <span class="n">tq</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
- <span class="k">try</span><span class="p">:</span>
- <span class="n">time_print</span><span class="p">(</span><span class="s2">"starting..."</span><span class="p">)</span>
- <span class="n">tq</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
- <span class="k">finally</span><span class="p">:</span>
- <span class="n">tq</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
- </pre></div>
- </div>
- <p>Will result to the following output:</p>
- <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>task.threaded_queue example:
- -------------------------------
- Thu Jan 7 17:33:50 2021: (Task 1) Hello from queue example (4)!
- Thu Jan 7 17:33:50 2021: starting...
- Thu Jan 7 17:33:54 2021: (Task 1) Ende!
- Thu Jan 7 17:33:54 2021: (Task 2) Hello from queue example (5)!
- Thu Jan 7 17:33:58 2021: (Task 2) Ende!
- Thu Jan 7 17:33:58 2021: (Task 3) Hello from queue example (6)!
- Thu Jan 7 17:34:01 2021: (Task 3) Ende!
- </pre></div>
- </div>
- <dl class="method">
- <dt id="task.threaded_queue.join">
- <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>
- <dd><p>This blocks till the queue is empty.</p>
- <div class="admonition note">
- <p class="first admonition-title">Note</p>
- <p class="last">If the queue does not run dry, join will block till the end of the days.</p>
- </div>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.threaded_queue.run">
- <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>
- <dd><p>This starts the execution of the queued callbacks.</p>
- </dd></dl>
-
- <dl class="method">
- <dt id="task.threaded_queue.stop">
- <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>
- <dd><p>This sets the stop flag. That means that the process will stop after finishing the active task.</p>
- </dd></dl>
-
- </dd></dl>
-
- </div>
- <div class="toctree-wrapper compound">
- </div>
- </div>
- <div class="section" id="indices-and-tables">
- <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
- <ul class="simple">
- <li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
- <li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
- <li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
- </ul>
- </div>
-
-
- </div>
-
- </div>
- <footer>
-
-
- <hr/>
-
- <div role="contentinfo">
- <p>
-
- © Copyright 2021, Dirk Alders
-
- </p>
- </div>
-
-
-
- Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
-
- <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
-
- provided by <a href="https://readthedocs.org">Read the Docs</a>.
-
- </footer>
-
- </div>
- </div>
-
- </section>
-
- </div>
-
-
- <script type="text/javascript">
- jQuery(function () {
- SphinxRtdTheme.Navigation.enable(true);
- });
- </script>
-
-
-
-
-
-
- </body>
- </html>
|