| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- <!DOCTYPE html>
- <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
- <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
- <head>
- <meta charset="utf-8">
-
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-
- <title>CBD.realtime.threadingPython — CBD Simulation Development Kit documentation</title>
-
-
-
-
-
-
-
-
-
-
- <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
- <!-- <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" /> -->
- <link rel="stylesheet" href="../../../_static/style.css" type="text/css" />
- <link rel="index" title="Index" href="../../../genindex.html" />
- <link rel="search" title="Search" href="../../../search.html" />
-
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-167094275-1"></script>
- <script src="../../../_static/js/googleanalytics.min.js"></script>
-
- <script src="../../../_static/js/modernizr.min.js"></script>
- <!-- Preload the theme fonts -->
- <link rel="preload" href="../../../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="../../../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="../../../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="../../../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="../../../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="../../../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <!-- Preload the katex fonts -->
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- <link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
- </head>
- <div class="container-fluid header-holder tutorials-header" id="header-holder">
- <div class="container">
- <div class="header-container">
- <a class="header-logo" href="https://catalyst-team.com/" aria-label="Catalyst"></a>
- <div class="main-menu">
- <ul>
- <li>
- <div class="ecosystem-dropdown">
- <a id="dropdownMenuButtonEcosystem" data-toggle="ecosystem-dropdown">
- Ecosystem
- </a>
- <div class="ecosystem-dropdown-menu">
- <a class="nav-dropdown-item" href="https://alchemy.host">
- <span class=dropdown-title>Alchemy</span>
- <p>Experiments logging & visualization</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/catalyst">
- <span class=dropdown-title>Catalyst</span>
- <p>Accelerated deep learning R&D</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/reaction">
- <span class=dropdown-title>Reaction</span>
- <p>Convenient deep learning models serving</p>
- </a>
- </div>
- </div>
- </li>
- <li>
- <div class="projects-dropdown">
- <a id="dropdownMenuButtonProjects" data-toggle="projects-dropdown">
- Projects
- </a>
- <div class="projects-dropdown-menu">
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/codestyle">
- <span class=dropdown-title>Codestyle</span>
- <p>Joint R&D codestyle</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/neuro">
- <span class=dropdown-title>Catalyst.Neuro</span>
- <p>Catalyst.Team and TReNDS collaborative project</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/classification">
- <span class=dropdown-title>Classification</span>
- <p>Image classification pipeline with transfer learning</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/detection">
- <span class=dropdown-title>Detection</span>
- <p>Object detection pipeline</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/segmentation">
- <span class=dropdown-title>Segmentation</span>
- <p>Image semantic segmentation pipeline</p>
- </a>
- <a class="nav-dropdown-item" href="https://github.com/catalyst-team/gan">
- <span class=dropdown-title>Catalyst.GAN</span>
- <p>GAN pipelines</p>
- </a>
- </div>
- </div>
- </li>
- <li>
- <a href="https://github.com/catalyst-team/dl-course">Deep learning course</a>
- </li>
- </ul>
- </div>
- <a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
- </div>
- </div>
- </div>
- <body class="catalyst-body">
-
-
- <div class="table-of-contents-link-wrapper">
- <span>Table of Contents</span>
- <a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
- </div>
- <nav data-toggle="wy-nav-shift" class="catalyst-left-menu" id="catalyst-left-menu">
- <div class="catalyst-side-scroll">
- <div class="catalyst-menu catalyst-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
- <div class="catalyst-left-menu-search">
-
-
-
-
-
-
-
- <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>
-
-
-
-
-
-
- <p class="caption"><span class="caption-text">Setup</span></p>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../../../install.html">How to install the CBD framework?</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../running.html">How to run a CBD simulation?</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../changelog.html">Changelog</a></li>
- </ul>
- <p class="caption"><span class="caption-text">Simple Examples</span></p>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/SinGen.html">Sine Generator</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/EvenNumberGen.html">Hierarchical Even Number Generator</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/Fibonacci.html">Fibonacci Sequence Generator</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/LCG.html">Linear Congruential Generator</a></li>
- </ul>
- <p class="caption"><span class="caption-text">Advanced Examples</span></p>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/RealTime.html">Realtime Simulation</a></li>
- <li class="toctree-l1"><a class="reference internal" href="../../../examples/LivePlot.html">Live Plotting of Data During the Simulation</a></li>
- </ul>
- <p class="caption"><span class="caption-text">Internal Documentation</span></p>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../../../CBD.html">CBD package</a></li>
- </ul>
-
-
- </div>
- </div>
- </nav>
- <div class="catalyst-container">
- <div class="catalyst-page-level-bar" id="catalyst-page-level-bar">
- <div class="catalyst-breadcrumbs-wrapper">
-
- <div role="navigation" aria-label="breadcrumbs navigation">
- <ul class="catalyst-breadcrumbs">
-
- <li>
- <a href="../../../index.html">
-
- Docs
-
- </a> >
- </li>
-
- <li><a href="../../index.html">Module code</a> ></li>
-
- <li>CBD.realtime.threadingPython</li>
-
-
- <li class="catalyst-breadcrumbs-aside">
-
- </li>
-
- </ul>
-
- </div>
- </div>
- <div class="catalyst-shortcuts-wrapper" id="catalyst-shortcuts-wrapper">
- Shortcuts
- </div>
- </div>
- <section data-toggle="wy-nav-shift" id="catalyst-content-wrap" class="catalyst-content-wrap">
- <div class="catalyst-content-left">
-
- <div class="rst-content">
-
- <div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
- <article itemprop="articleBody" id="catalyst-article" class="catalyst-article">
-
- <h1>Source code for CBD.realtime.threadingPython</h1><div class="highlight"><pre>
- <span></span><span class="c1"># Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at </span>
- <span class="c1"># McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)</span>
- <span class="c1"># </span>
- <span class="c1"># Licensed under the Apache License, Version 2.0 (the "License");</span>
- <span class="c1"># you may not use this file except in compliance with the License.</span>
- <span class="c1"># You may obtain a copy of the License at</span>
- <span class="c1">#</span>
- <span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span>
- <span class="c1">#</span>
- <span class="c1"># Unless required by applicable law or agreed to in writing, software</span>
- <span class="c1"># distributed under the License is distributed on an "AS IS" BASIS,</span>
- <span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
- <span class="c1"># See the License for the specific language governing permissions and</span>
- <span class="c1"># limitations under the License.</span>
- <span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Event</span><span class="p">,</span> <span class="n">Thread</span><span class="p">,</span> <span class="n">Lock</span>
- <span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">accurate_time</span> <span class="k">as</span> <span class="n">time</span>
- <div class="viewcode-block" id="ThreadingPython"><a class="viewcode-back" href="../../../CBD.realtime.threadingPython.html#CBD.realtime.threadingPython.ThreadingPython">[docs]</a><span class="k">class</span> <span class="nc">ThreadingPython</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
- <span class="sd">"""</span>
- <span class="sd"> Simple Python threads subsystem</span>
- <span class="sd"> """</span>
- <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="sd">"""</span>
- <span class="sd"> Constructor</span>
- <span class="sd"> """</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">evt</span> <span class="o">=</span> <span class="n">Event</span><span class="p">()</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">evt_lock</span> <span class="o">=</span> <span class="n">Lock</span><span class="p">()</span>
- <div class="viewcode-block" id="ThreadingPython.wait"><a class="viewcode-back" href="../../../CBD.realtime.threadingPython.html#CBD.realtime.threadingPython.ThreadingPython.wait">[docs]</a> <span class="k">def</span> <span class="nf">wait</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">delay</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
- <span class="sd">"""</span>
- <span class="sd"> Wait for the specified time, or faster if interrupted</span>
- <span class="sd"> :param delay: time to wait</span>
- <span class="sd"> :param func: the function to call</span>
- <span class="sd"> """</span>
- <span class="c1">#NOTE this call has a granularity of 5ms in Python <= 2.7.x in the worst case, so beware!</span>
- <span class="c1"># the granularity seems to be much better in Python >= 3.x</span>
- <span class="n">p</span> <span class="o">=</span> <span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">ThreadingPython</span><span class="o">.</span><span class="n">callFunc</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="bp">self</span><span class="p">,</span> <span class="n">delay</span><span class="p">,</span> <span class="n">func</span><span class="p">])</span>
- <span class="n">p</span><span class="o">.</span><span class="n">daemon</span> <span class="o">=</span> <span class="kc">True</span>
- <span class="n">p</span><span class="o">.</span><span class="n">start</span><span class="p">()</span></div>
- <div class="viewcode-block" id="ThreadingPython.interrupt"><a class="viewcode-back" href="../../../CBD.realtime.threadingPython.html#CBD.realtime.threadingPython.ThreadingPython.interrupt">[docs]</a> <span class="k">def</span> <span class="nf">interrupt</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
- <span class="sd">"""</span>
- <span class="sd"> Interrupt the waiting thread</span>
- <span class="sd"> """</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">evt</span><span class="o">.</span><span class="n">set</span><span class="p">()</span></div>
- <div class="viewcode-block" id="ThreadingPython.callFunc"><a class="viewcode-back" href="../../../CBD.realtime.threadingPython.html#CBD.realtime.threadingPython.ThreadingPython.callFunc">[docs]</a> <span class="k">def</span> <span class="nf">callFunc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">delay</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
- <span class="sd">"""</span>
- <span class="sd"> Function to call on a seperate thread: will block for the</span>
- <span class="sd"> specified time and call the function afterwards</span>
- <span class="sd"> Args:</span>
- <span class="sd"> delay (float): The wait delay.</span>
- <span class="sd"> func: The function to call. No arguments can be</span>
- <span class="sd"> used and no return values are needed.</span>
- <span class="sd"> """</span>
- <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">evt_lock</span><span class="p">:</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">evt</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="n">delay</span><span class="p">)</span>
- <span class="n">func</span><span class="p">()</span>
- <span class="bp">self</span><span class="o">.</span><span class="n">evt</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span></div></div>
- </pre></div>
- </article>
-
- </div>
- <footer>
-
- <hr>
- <div role="contentinfo">
- <p>
- © Copyright 2020, Randy Paredis.
- </p>
- </div>
-
- <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>.
- </div>
-
- </footer>
- </div>
- </div>
- <div class="catalyst-content-right" id="catalyst-content-right">
- <div class="catalyst-right-menu" id="catalyst-right-menu">
- <div class="catalyst-side-scroll" id="catalyst-side-scroll-right">
-
- </div>
- </div>
- </div>
- </section>
- </div>
-
-
-
- <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 async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
-
-
- <script type="text/javascript" src="../../../_static/js/vendor/popper.min.js"></script>
- <script type="text/javascript" src="../../../_static/js/vendor/bootstrap.min.js"></script>
- <script type="text/javascript" src="../../../_static/js/theme.js"></script>
- <script type="text/javascript">
- jQuery(function () {
- SphinxRtdTheme.Navigation.enable(true);
- });
- </script>
- <!-- Begin Footer -->
- <footer class="site-footer" id="site-footer">
- <div class="container footer-container">
- <div class="footer-logo-wrapper">
- <a href="https://catalyst-team.com/" class="footer-logo"></a>
- </div>
- <div class="footer-links-wrapper">
- <div class="footer-links-col">
- <ul>
- <li class="list-title"><a href="https://github.com/catalyst-team">Ecosystem</a></li>
- <li><a class="nav-dropdown-item" href="https://alchemy.host">Alchemy</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/catalyst">Catalyst</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/reaction">Reaction</a></li>
- </ul>
- </div>
- <div class="footer-links-col">
- <ul>
- <li class="list-title"><a href="https://github.com/catalyst-team">Projects</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/codestyle">Codestyle</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/neuro">Catalyst.Neuro</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/classification">Classification</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/detection">Detection</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/segmentation">Segmentation</a></li>
- <li><a class="nav-dropdown-item" href="https://github.com/catalyst-team/gan">Catalyst.GAN</a></li>
- </ul>
- </div>
- <div class="footer-links-col">
- <ul>
- <li class="list-title"><a href="https://catalyst-team.com/">Support</a></li>
- <li><a href="https://github.com/catalyst-team/catalyst/issues" target="_blank">Github Issues</a></li>
- <li><a href="https://github.com/catalyst-team/catalyst/blob/master/CONTRIBUTING.md" target="_blank">Contributing</a></li>
- <li><a href="https://www.patreon.com/catalyst_team" target="_blank">Patreon</a></li>
- </ul>
- </div>
- <div class="footer-links-col follow-us-col">
- <div class="footer-social-icons">
- <a href="https://t.me/catalyst_team" target="_blank" class="telegram"></a>
- <a href="https://twitter.com/catalyst_core" target="_blank" class="twitter"></a>
- <a href="https://join.slack.com/t/catalyst-team-core/shared_invite/zt-d9miirnn-z86oKDzFMKlMG4fgFdZafw" target="_blank" class="ods"></a>
- </div>
- </div>
- </div>
- </div>
- </footer>
- <!-- End Footer -->
- <!-- Begin Mobile Menu -->
- <div class="mobile-main-menu">
- <div class="container-fluid">
- <div class="container">
- <div class="mobile-main-menu-header-container">
- <a class="header-logo" href="https://catalyst-team.com/" aria-label="Catalyst"></a>
- <a class="main-menu-close-button" href="#" data-behavior="close-mobile-menu"></a>
- </div>
- </div>
- </div>
- <div class="mobile-main-menu-links-container">
- <div class="main-menu">
- <ul>
- <li>
- <a href="">Get Started</a>
- </li>
- <li>
- <a href="https://github.com/catalyst-team/catalyst">Github</a>
- </li>
- </ul>
- </div>
- </div>
- </div>
- <!-- End Mobile Menu -->
- <script type="text/javascript" src="../../../_static/js/vendor/anchor.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- mobileMenu.bind();
- mobileTOC.bind();
- catalystAnchors.bind();
- sideMenus.bind();
- scrollToAnchor.bind();
- highlightNavigation.bind();
- mainMenuDropdown.bind();
- // Add class to links that have code blocks, since we cannot create links in code blocks
- $("article.catalyst-article a span.pre").each(function(e) {
- $(this).closest("a").addClass("has-code");
- });
- })
- </script>
- </body>
- </html>
|