Page 1 of 1

I want to use REPL while using uasyncio

Posted: Wed Jun 06, 2018 5:03 am
by Meekdai
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?

Re: I want to use REPL while using uasyncio

Posted: Wed Jun 06, 2018 7:35 am
by pythoncoder
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.

Re: I want to use REPL while using uasyncio

Posted: Wed Jun 06, 2018 7:48 am
by Meekdai
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, ) )

Re: I want to use REPL while using uasyncio

Posted: Mon May 29, 2023 4:46 am
by FraggaMuffin