<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Creating an infinite async loop]]></title><description><![CDATA[<p dir="auto">Looking to write code that will send data via mqtt perpetually. Learn recently that the publish() method is NOT synchronous, which I augmented by listening to a topic for an ack message before calling the iteration done, and the next iteration publish begins.</p>
<p dir="auto">So I tried to close the loop by calling the publish() method within the subscribe() handler, and the app crashed with message 'RuntimeError: maximum recursion depth exceeded'.</p>
<p dir="auto">How do people get around this?</p>
]]></description><link>https://community.m5stack.com/topic/2044/creating-an-infinite-async-loop</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 00:41:02 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2044.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Jun 2020 11:15:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Creating an infinite async loop on Mon, 15 Jun 2020 15:45:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/m5stack" aria-label="Profile: m5stack">@<bdi>m5stack</bdi></a> I will share pseudo-codes of the current implementation, which is stable so far:</p>
<pre><code class="language-py">CycleTimer = Timer(-1)

def main():
  # init and connect mqtt client
  doCycle()

def doCycle():
  global CycleTimer
  # send stuff from mqtt
  # NOTE: do not use machine.lightsleep() as publish() is NOT synchronous
  # lightsleep() will block data from being sent
  CycleTimer.init(period=5000, mode=Timer.ONE_SHOT, callback=doCycle)    
</code></pre>
<p dir="auto">NOTE: this is power-intensive; calling lightsleep() will cause uiflow's mqtt client to crash quickly.</p>
]]></description><link>https://community.m5stack.com/post/9010</link><guid isPermaLink="true">https://community.m5stack.com/post/9010</guid><dc:creator><![CDATA[jhfoo]]></dc:creator><pubDate>Mon, 15 Jun 2020 15:45:27 GMT</pubDate></item><item><title><![CDATA[Reply to Creating an infinite async loop on Mon, 15 Jun 2020 09:53:41 GMT]]></title><description><![CDATA[<p dir="auto">could you share your code to here. maybe people can help you.</p>
]]></description><link>https://community.m5stack.com/post/9008</link><guid isPermaLink="true">https://community.m5stack.com/post/9008</guid><dc:creator><![CDATA[m5stack]]></dc:creator><pubDate>Mon, 15 Jun 2020 09:53:41 GMT</pubDate></item><item><title><![CDATA[Reply to Creating an infinite async loop on Sun, 14 Jun 2020 16:33:51 GMT]]></title><description><![CDATA[<p dir="auto">Am trying using ONE_SHOT timers. Not sure if this is the recommended approach.</p>
]]></description><link>https://community.m5stack.com/post/9002</link><guid isPermaLink="true">https://community.m5stack.com/post/9002</guid><dc:creator><![CDATA[jhfoo]]></dc:creator><pubDate>Sun, 14 Jun 2020 16:33:51 GMT</pubDate></item></channel></rss>