spacemanspiff2007 / PyArtNet

"Python wrappers for the Art-Net protocol to send DMX over Ethernet"
GNU General Public License v3.0
67 stars 13 forks source link

getting a SyntaxError: 'await' outside function #10

Closed high-solutions closed 3 years ago

high-solutions commented 3 years ago

I'm fairly new to Python so it may be me not understanding how to implement asyncio or async definitions but i can't get past the "read me" "usage" "fades" example, i'm getting an error: await node.start() ^ SyntaxError: 'await' outside function

I'm using version 0.8.2 and in the artnet_node.py the start function is in a 'async def' as an executable statement as it should be so i'm not sure why it's not working.

I tried putting await node.start() in a async def and in a normal def in my script but the error stays the same

Can you explain a little more how to use/start with PyArtNet in the readme?

spacemanspiff2007 commented 3 years ago

Imho it's best to start with an asyncio tutorial so you learn how all this async stuff works.

import asyncio

async def async_func():
    node = ArtNetNode('IP')
    await node.start()

    universe = node.add_universe(0)
    channel  = universe.add_channel(start=1, width=3)

    while True:
        channel.add_fade([255,0,0], 5000)
        await channel.wait_till_fade_complete()
        await asyncio.sleep(1)

asyncio.run(async_func())