Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    _thread vs uasyncio

    Scheduled Pinned Locked Moved MicroPython
    uasynciothread
    10 Posts 6 Posters 206 Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tttadam
      last edited by

      Hello there,

      My project needs multithreading, and some kind of locks.
      As far as I know _thread is not support any kind of locks.
      So do you know a workaround of that?
      uasyncio could be one, but it is not supported on pycom boards. Is there a way to use it?
      Which path should I choose?

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @tttadam
        last edited by livius

        @tttadam said in _thread vs uasyncio:

        As far as I know _thread is not support any kind of locks.

        What about this?
        https://docs.pycom.io/firmwareapi/micropython/_thread/#class-lock

        think about people first, then computers

        T 1 Reply Last reply Reply Quote 3
        • T Offline
          tttadam @livius
          last edited by

          @livius That is new. Least for me. I haven't use pycom boards for a year now. Thanks! :)

          1 Reply Last reply Reply Quote 0
          • J Offline
            JSmith
            last edited by

            Hi guys, this topic is similar to my current issue.

            I see uasyncio was supposed to be supported as per: https://forum.pycom.io/topic/3480/new-firmware-development-release-v1-19-0-b4/15

            This would be brilliant for my scheduling requirements, and since I am running firmware: 1.20.2.r2 I attempted to use this using upip install, as per: https://medium.com/@chrismisztur/pycom-uasyncio-installation-94931fc71283

            However I cannot seem to use the library as I get error: "AttributeError: 'module' object has no attribute 'run'" if I try and run any of the tutorial code.

            I assume the pip install has installed V3 uasyncio. Is this supported? Or could anyone help point me at direction for installing uasyncio?

            Kind regards, Jake

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @JSmith
              last edited by

              @JSmith Uasyncio V3 is not supported. The Pycom firmware still sticks to an old version of the MicroPython core, and even for uasyncio V2 there is a pitfall, which is the order of arguments of ticks_diff.

              J 1 Reply Last reply Reply Quote 1
              • J Offline
                JSmith @robert-hh
                last edited by

                @robert-hh thank you very much for the insight.

                Is V2 the version that was supposed to be supported in: https://forum.pycom.io/topic/3480/new-firmware-development-release-v1-19-0-b4 ?

                I suppose what I am trying to understand is if there is anyway I can get a version of uasyncio working on my Wipy3.0?

                robert-hhR 1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @JSmith
                  last edited by

                  @JSmith I have a working subset which is good for 1.20.2.r4. Part of that is from micropython-lib/uasyncio in a maybe older version. https://github.com/micropython/micropython-lib.
                  I did not use that a lot, but what I appended works. So it may be a starting point. I could not add an archive here, so you'll find it here: https://github.com/robert-hh/Shared-Stuff/blob/master/uasyncio.zip

                  J 1 Reply Last reply Reply Quote 2
                  • J Offline
                    JSmith @robert-hh
                    last edited by

                    @robert-hh I have downloaded, and updated firmware and confirm it works!

                    Thanks for you awesome support!

                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      peterp
                      last edited by peterp

                      FWIW, I just made a really short test, took the folder from https://github.com/micropython/micropython/tree/master/extmod/uasyncio and ran their simple 'hello world' example. that worked ok. Haven't tested deeper.

                      import uasyncio
                      
                      async def blink(led, period_ms):
                          while True:
                              print(led, 'on')
                              await uasyncio.sleep_ms(5)
                              print(led, 'off')
                              await uasyncio.sleep_ms(period_ms)
                      
                      async def main(led1, led2):
                          uasyncio.create_task(blink(led1, 700))
                          uasyncio.create_task(blink(led2, 400))
                          await uasyncio.sleep_ms(10_000)
                      
                      uasyncio.run(main(4,5))
                      

                      I tested on 1.20.3.b3

                      B 1 Reply Last reply Reply Quote 0
                      • B Offline
                        Brian Wyld @peterp
                        last edited by

                        @peterp Note that the 'event.py' which defines a semaphore for asyncio does not load on the latest version, as it depends (for ThreadSafeFlag) on being able to extend uio.IOBase. This base class is not used in the pycom micropython uio port apparently...
                        This is an issue to use asyncio on pycom ports as ThreadSafeFlag is the only way to do a semaphore from an ISR or other _thread task...

                        any ideas?

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • 1 / 1
                        • First post
                          Last post

                        Pycom on Twitter

                        Pycom