You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1>What are the differences between <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a>?<aclass="headerlink" href="#what-are-the-differences-between-asyncio-and-cothread" title="Permalink to this headline"></a></h1>
102
-
<p>There are two concurrency frameworks that pythonSoftIOC supports, <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and
101
+
<h1>What are the differences between <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a>?<aclass="headerlink" href="#what-are-the-differences-between-asyncio-and-cothread" title="Permalink to this headline"></a></h1>
102
+
<p>There are two concurrency frameworks that pythonSoftIOC supports, <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and
103
103
<aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a>. This page details the differences between them and reasons why you
<h2>The Differences<aclass="headerlink" href="#the-differences" title="Permalink to this headline"></a></h2>
124
124
<p>The main difference between the libraries is how a coroutine yields control.</p>
125
125
<ulclass="simple">
126
-
<li><p><aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> uses an <codeclass="docutils literal notranslate"><spanclass="pre">async</span><spanclass="pre">def</span></code> which will yield control when they <codeclass="docutils literal notranslate"><spanclass="pre">await</span></code>.
126
+
<li><p><aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> uses an <codeclass="docutils literal notranslate"><spanclass="pre">async</span><spanclass="pre">def</span></code> which will yield control when they <codeclass="docutils literal notranslate"><spanclass="pre">await</span></code>.
127
127
Only an <codeclass="docutils literal notranslate"><spanclass="pre">async</span><spanclass="pre">def</span></code> can <codeclass="docutils literal notranslate"><spanclass="pre">await</span></code> another <codeclass="docutils literal notranslate"><spanclass="pre">async</span><spanclass="pre">def</span></code>, so functions that
128
128
yield control are explicitly marked as such by the presence of the <codeclass="docutils literal notranslate"><spanclass="pre">async</span></code>
<h2>Which to use<aclass="headerlink" href="#which-to-use" title="Permalink to this headline"></a></h2>
172
172
<p>There are some questions to ask to help you choose which one to use:</p>
173
173
<ulclass="simple">
174
-
<li><p>If you run python2.7 then you need to use <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a> as <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> is python3
174
+
<li><p>If you run python2.7 then you need to use <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a> as <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> is python3
175
175
only</p></li>
176
-
<li><p>If you run on Windows then you need <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> as <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a> doesn’t work on
176
+
<li><p>If you run on Windows then you need <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> as <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a> doesn’t work on
177
177
Windows</p></li>
178
-
<li><p>If you need to integrate with a library that uses <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> like one from
179
-
<aclass="reference external" href="https://github.com/aio-libs">aio-libs</a> then use <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a></p></li>
178
+
<li><p>If you need to integrate with a library that uses <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> like one from
179
+
<aclass="reference external" href="https://github.com/aio-libs">aio-libs</a> then use <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a></p></li>
180
180
<li><p>If you need to turn a script using <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/catools.html#module-cothread.catools" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread.catools</span></code></a> into an IOC then use
181
181
<aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a></p></li>
182
182
</ul>
183
183
<p>In general, avoid mixing concurrency frameworks if you can. While it is possible
184
-
to mix <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.11)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a>, it’s messy and tricky to get right. Better to
184
+
to mix <aclass="reference external" href="https://docs.python.org/3/library/asyncio.html#module-asyncio" title="(in Python v3.12)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">asyncio</span></code></a> and <aclass="reference external" href="https://cothread.readthedocs.io/en/stable/cothread.html#module-cothread" title="(in Cothread)"><codeclass="xref any docutils literal notranslate"><spanclass="pre">cothread</span></code></a>, it’s messy and tricky to get right. Better to
0 commit comments