0

I am actually on a project that needs concurentials functions... but I don't really know (and understand) a lot about it. My program must run on a Raspberry pi pico with Circuitpython. I did some research and the most suitable library for this is Asyncio.

Here is in a nutshell my program:

async def playAudio(import 1, import 2):
   *some actions....*
   print("audio") #added this to debug
   if audio not played yet:
      playAudio()

async def lcdScreen(import 1, import 2):
    
    print("LCD") #added this to debug
    *some actions....*
    lcd.print("*something*")
    time.sleep(1)
    lcd.print("*something else*")
    time.sleep(1)

async def story(imports of both functions)
    L = await asyncio.gather(
       playAudio(imports),
       playAudio(imports),
      )
    print(l)

while True:
   *some actions....*

   asyncio.run(story(*all imports)

When I run the program, I get:

Audio
*then a while later:*
LCD

This might be a beginner problem, but I can't figure out how to make this work. I checked online and saw that I need ```await``, but again can't figure out how to apply it to this case :(

I imported Asyncio with Circup from a Windows 11

Thanks for your help !

NOTE: I tried to follow examples from Asyncio Library

4
  • Remember that asyncio only runs things concurrently, but not in parallel. If your code never yields control back to the scheduler (by calling await on something), then other async coroutines will never have the chance to run. Because playAudio never calls await, nothing else can run until the function completes. Commented Mar 15, 2024 at 10:50
  • Thank's @larsks for your comment. Isn't there any way yo make them work in parallel ? Or do I have to buy another pico to run the audio script ? Commented Mar 15, 2024 at 11:12
  • I don't think there's enough of your code here to answer that question. It's not clear how playAudio is implemented, and in the sample you've posted nothing actually calls lcdScreen. Commented Mar 15, 2024 at 19:18
  • Thanks again for your anwser. I actually followed your advice and tried to find another way to run my program without parallel running functions. You are right, my sample is quite lite, but I tried to give in the simpliest way my program just to show what I wanted. Commented Mar 18, 2024 at 15:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.