2

What am I doing wrong? When I run this,

import asyncio
def oneSecond():
    await asyncio.sleep(1)

I get this:

File "<string>", line 3
await asyncio.sleep(1)
            ^
SyntaxError: invalid syntax

Using Python 3.3

2
  • Which Python version? Commented Sep 21, 2017 at 13:51
  • Sorry, Python 3.3 Commented Sep 21, 2017 at 13:51

1 Answer 1

7

You are using the await keyword with Python 3.3 but it has not been added to Python before version 3.5. You should upgrade your Python version.

Also you will have to define your function as async:

async def oneSecond():
    await asyncio.sleep(1)
Sign up to request clarification or add additional context in comments.

4 Comments

Identical problem on 3.5.1
I edited the the answer with an additional problem being solved.
Now when I do await oneSecond() it's a syntax error.
You have to start it inside asyncio event loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.