I want to use REPL while using uasyncio

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

I want to use REPL while using uasyncio

Post by Meekdai » Wed Jun 06, 2018 5:03 am

When using uasyncio, the program is looping and cannot use REPL.Is there a way to achieve both at the same time?
Here is my code:

Code: Select all

import uasyncio as asyncio

async def blink1():
    bled=LED(4)
    while True:
        bled.toggle()
        await asyncio.sleep_ms(1000)

async def blink2():
    gled = LED(2)
    while True:
        gled.toggle()
        await asyncio.sleep_ms(2000)

loop = asyncio.get_event_loop()
loop.create_task(blink1())
loop.create_task(blink2())
loop.run_forever()
I try to use REPL while using _thread, It is working. But this article says “Threads Are Bad”. what should I do?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I want to use REPL while using uasyncio

Post by pythoncoder » Wed Jun 06, 2018 7:35 am

When a Python program is running the REPL is unavailable. This is normal behaviour for Python and is independent of MicroPython, uasyncio or anything else. The REPL is there to launch programs and to examine their behaviour after they stop (intentionally or owing to an error) or are interrupted.

The purpose of uasyncio is to enable individual program tasks to run with an illusion of concurrency; it doesn't provide a means of running the REPL concurrently with a program.

As to whether what you want is achievable with _thread the short answer is that I don't know.
Peter Hinch
Index to my micropython libraries.

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: I want to use REPL while using uasyncio

Post by Meekdai » Wed Jun 06, 2018 7:48 am

Thanks , I use _thread to solve my problem.
I found that when using _thread , REPL work well.

Code: Select all

import _thread
import time

def blink( threadName, delay):
    gled = LED(2)
    while True:
        gled.toggle()
        time.sleep_ms(delay)

Tblink=_thread.start_new_thread( blink, ("Thread-1", 500, ) )

User avatar
FraggaMuffin
Posts: 9
Joined: Sat Nov 11, 2017 1:10 am
Location: Melbourne, Australia
Contact:

Re: I want to use REPL while using uasyncio

Post by FraggaMuffin » Mon May 29, 2023 4:46 am


Post Reply