Alternative code emitters and generators

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Alternative code emitters and generators

Post by pythoncoder » Tue Aug 19, 2014 3:49 pm

Is there any way to apply the alternative code emitters to generators? I'm using generators to implement lightweight threads and there's a potential performance benefit in using these but my tests so far have failed. The following issues a "TypeError: 'NoneType' object is not an iterator" on the print line unless I comment out the decorator.

Code: Select all

@micropython.native
def myfunc():
    for x in range(10):
        yield 2*x

gen = myfunc()
while True:
    try:
        print(next(gen))
    except StopIteration:
        break
Regards, Pete
Peter Hinch
Index to my micropython libraries.

Post Reply