Python uasyncio.new_event_loop() Examples

The following are 16 code examples of uasyncio.new_event_loop(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module uasyncio , or try the search function .
Example #1
Source File: art.py    From micropython-async with MIT License 6 votes vote down vote up
def test():
    print('Test for IR receiver. Assumes NEC protocol.')
    print('ctrl-c to stop.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
    elif ESP32:
        p = Pin(23, Pin.IN)
    ir = NEC_IR(p, cb, True)  # Assume r/c uses extended addressing
    loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()  # Still need ctrl-d because of interrupt vector 
Example #2
Source File: art1.py    From micropython-async with MIT License 6 votes vote down vote up
def test():
    print('Test for IR receiver. Assumes NEC protocol. Turn LED on or off.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
        led = LED(2)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
        led = Pin(2, Pin.OUT)
        led(1)
    elif ESP32:
        p = Pin(23, Pin.IN)
        led = Pin(21, Pin.OUT)  # LED with 220Ω series resistor between 3.3V and pin 21
        led(1)
    ir = NEC_IR(p, cb, True, led)  # Assume extended address mode r/c
    loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()  # Still need ctrl-d because of interrupt vector 
Example #3
Source File: asnano_sync.py    From micropython-nano-gui with MIT License 5 votes vote down vote up
def test():
    try:
        asyncio.run(main())
    finally:  # Reset uasyncio case of KeyboardInterrupt
        asyncio.new_event_loop()
        print('asnano_sync.test() to re-run test.') 
Example #4
Source File: s_app.py    From micropython-iot with MIT License 5 votes vote down vote up
def run():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        print('Closing sockets')
        server.Connection.close_all()
        asyncio.new_event_loop() 
Example #5
Source File: s_app_cp.py    From micropython-iot with MIT License 5 votes vote down vote up
def run():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        print('Closing sockets')
        server.Connection.close_all()
        asyncio.new_event_loop() 
Example #6
Source File: s_qos_cp.py    From micropython-iot with MIT License 5 votes vote down vote up
def run():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        print('Closing sockets')
        server.Connection.close_all()
        asyncio.new_event_loop() 
Example #7
Source File: s_qos_fast.py    From micropython-iot with MIT License 5 votes vote down vote up
def run():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        print('Closing sockets')
        server.Connection.close_all()
        asyncio.new_event_loop() 
Example #8
Source File: s_comms_cp.py    From micropython-iot with MIT License 5 votes vote down vote up
def run():
    clients = {'rx', 'tx'}  # Expected clients
    apps = [App(name) for name in clients]  # Accept 2 clients
    try:
        asyncio.run(server.run(clients, verbose=True, port=PORT, timeout=TIMEOUT))
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        print('Closing sockets')
        server.Connection.close_all()
        asyncio.new_event_loop() 
Example #9
Source File: ugui.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def change(cls, cls_new_screen, *, forward=True, args=[], kwargs={}):
        init = cls.current_screen is None
        if init:
            Screen() # Instantiate a blank starting screen
        else:  # About to erase an existing screen
            for entry in cls.current_screen.tasklist:
                if entry[1]:  # To be cancelled on screen change
                    entry[0].cancel()
        cs_old = cls.current_screen
        cs_old.on_hide() # Optional method in subclass
        if forward:
            if isinstance(cls_new_screen, ClassType):
                new_screen = cls_new_screen(*args, **kwargs) # Instantiate new screen
            else:
                raise ValueError('Must pass Screen class or subclass (not instance)')
            new_screen.parent = cs_old
            cs_new = new_screen
        else:
            cs_new = cls_new_screen # An object, not a class
        cls.current_screen = cs_new
        cs_new.on_open() # Optional subclass method
        cs_new._do_open(cs_old) # Clear and redraw
        cs_new.after_open() # Optional subclass method
        if init:
            try:
                asyncio.run(Screen.monitor())  # Starts and ends uasyncio
            finally:
                asyncio.new_event_loop()
                gc.collect() 
Example #10
Source File: adctest.py    From micropython-async with MIT License 5 votes vote down vote up
def test():
    try:
        asyncio.run(adctest())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print()
        print(st) 
Example #11
Source File: delay_test.py    From micropython-async with MIT License 5 votes vote down vote up
def test(n=0):
    try:
        asyncio.run(tests[n]())
    finally:
        asyncio.new_event_loop() 
Example #12
Source File: switches.py    From micropython-async with MIT License 5 votes vote down vote up
def run():
    try:
        asyncio.run(killer())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print(tests)


# Test for the Switch class passing coros 
Example #13
Source File: gather.py    From micropython-async with MIT License 5 votes vote down vote up
def test(rex):
    st = exp_true if rex else exp_false
    printexp(st)
    try:
        asyncio.run(main(rex))
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print()
        print('as_demos.gather.test() to run again.')
        print('as_demos.gather.test(True) to see effect of return_exceptions.') 
Example #14
Source File: auart.py    From micropython-async with MIT License 5 votes vote down vote up
def test():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print('as_demos.auart.test() to run again.') 
Example #15
Source File: aledflash.py    From micropython-async with MIT License 5 votes vote down vote up
def test(duration=10):
    try:
        asyncio.run(main(duration))
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print('as_demos.aledflash.test() to run again.') 
Example #16
Source File: auart_hd.py    From micropython-async with MIT License 5 votes vote down vote up
def test():
    printexp()
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()
        print('as_demos.auart_hd.test() to run again.')