question

MikeBond-8969 avatar image
0 Votes"
MikeBond-8969 asked MalteWinckler answered

Python Web App using "asyncio" not starting, has "invalid syntax" error

I have a Flask application that uses "asyncio" and using Python Web App deployment. It runs locally within docker with no issues.
After deploying the applications, it refuses to start with an "invalid syntax" error within the standard "asyncio" library.

This happens with either of the Python 3.7 or 3.8 containers.

Error output (example):
<log cut for brevity>
2021-01-13T17:22:33.533861769Z File "/antenv/lib/python3.7/site-packages/asyncio/init.py", line 21, in <module>
2021-01-13T17:22:33.533865470Z from .base_events import *
2021-01-13T17:22:33.533869570Z File "/antenv/lib/python3.7/site-packages/asyncio/base_events.py", line 296
2021-01-13T17:22:33.533873370Z future = tasks.async(future, loop=self)
2021-01-13T17:22:33.533876770Z ^
2021-01-13T17:22:33.533880170Z SyntaxError: invalid syntax

Any suggestions on why this runs fine in local docker but not on the deployed container?

azure-webapps
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Same issue here.

@Grmacjon-MSFT : did you see @MikeBond-8969 's reply ? I think you missed the point and didn't actually solve the issue. We still need your help on this ;)

Did anyone find a solution / workaround ?

0 Votes 0 ·

Hi,

I have found a solution replacing the whole asyncio library folder by the one updated by the github community.

Go to the following link, download the asyncio folder and replace it in your project after deployment, and give it a try.

https://github.com/python/cpython/tree/main/Lib

Kind regards,

0 Votes 0 ·
Grmacjon-MSFT avatar image
0 Votes"
Grmacjon-MSFT answered MikeBond-8969 edited

Hi @MikeBond-8969,

You could try re-installing Python 3.8 to fix this issue or follow the solutions provided in this similar SO post

"From version 3.7 async and await are reserved keywords. Copy and open the path (without init.py). You will get a list of .py files
Rename async.py to _async.py or anything you want, as async is now a reserved keyword with us from version 3.7. Once renamed, modify the new name everywhere."

if the issue persists please let us know so we can investigate further.

Thanks,
Grace

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

See my post to this question as the comment "Submit" button wasn't working.

The text in the additional post to this question prevents the comment from being submitted.
Even though it is under 1000 chars.???? Why???

0 Votes 0 ·
MikeBond-8969 avatar image
0 Votes"
MikeBond-8969 answered

TRIED TO SUBMIT A COMMENT - The "Submit" button doesn't work in Edge, Chrome, Firefox, or Safari

Please note the following:

1) This is coming from the BASE Python library for asyncio and has the same error in Python 3.7 and 3.8. What you aren't seeing from the screenshot is that further up in the stacktrace, it is triggered by an "import asyncio" line (base Python, not a PyPi install).
2) Re-installing Python is not an option as this is running in a docker appsvc container provided by Microsoft Azure App Service Python deployments.
3) This works fine in my local docker container using a slightly older container: "appsvc/python:3.8_20200522.6"
4) This works fine running in Python 3.8 under WSL2 also.
5) I realize that "async" and "await" are reserved Python keywords, this is not the issue.

Yes, I saw that article when originally looking into this issue, that is not what is happening here.
Question: Does Microsoft have some specific kernel options enabled/disabled?

I completely rewrote my the "asyncio" library for my application to remove the Python "asyncio" library dependency and it works fine.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AshishKesarkar avatar image
0 Votes"
AshishKesarkar answered

Im getting exact same error. Im also running it on Azure WebApp
Is there any easiest solution to this other than rewriting library?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ShadowSkye-2136 avatar image
0 Votes"
ShadowSkye-2136 answered

Same problem.

If I SSH into the server and run my app from the shell it works fine. But I cannot get the app to run on startup automatically...

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CliversonObrzut-7883 avatar image
0 Votes"
CliversonObrzut-7883 answered

I´m also getting the same issue using Python 3.9. Any simple solution?

![124027-image.png][1]



image.png (19.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MalteWinckler avatar image
0 Votes"
MalteWinckler answered

Hi, initially, I also had the same error with the deployed container. For me simply excluding the asyncio from the pip-requirements did the trick. When you are using Python >= 3.4, asyncio comes with Python as a provisional package.

Cheers, Malte

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.