Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asyncio Webserver
#1
I created a custom web server in Python using Asyncio that I thought I'd share with the Python community. It hosts both Python and static code (HTML/CSS/etc.), does SSL/TLS, and much more. Python pages can be created similar to how CherryPy works. Sending a class as an object to the web server for processing. It may not be production quality but it works quite well on both Windows and Linux. Thanks for taking a look.

Webserver on Github
Reply
#2
Even if we will not dive into the code, it could be seen that the usage part of the readme file lacks of details. It doesn't demonstrate any program functionality, e.g. how does it support url-routing, how to handle get/post requests with vars, what about wsgi etc.

If we look at the second line of the code in readme.rst, the question will arise: Does it really necessary to inherit from object here?

What about memory consumption of , e.g. call_static function (wserver.py). It includes line f.read() that means a static file (may be quite huge, e.g. video file) will be loaded into memory. This will probably lead to crash of the webserver?!

Did you look at the aiohttp package? May it be more useful, if we plan to process http-requests?

I think, there are lots of questions regarding the code .
Reply
#3
Thanks for your comments. I've been working with Python for about a year now (former VB.Net programmer) so I still have a lot to learn. Some of the code is not perfect simply do to my lack of knowledge about Python. While it may be a bad philosophy, I enjoy figuring out how things work and sometimes I like reinventing the wheel.

To answer some of your questions, yes the documentation can be improved. Routing is done similar to CherryPy in that your functions are the URLs. I'm sure the code could be improved for loading static files as well. I wrote the app to support my monitoring project so the design parameters didn't call for loading video, etc. and I did not take this into account.
Reply
#4
I think it's fascinating that this was posted 6 months ago, and the OP still replied to a comment without hours.

Anyway, if it works, that's a pretty big accomplishment for something using async. Nice job.
When it comes to other people looking at your code, it helps to have a similar style. For python, we have what's known as pep8: https://www.python.org/dev/peps/pep-0008/

Some of the things it goes into can be done automatically for you by a code formatter such as black or autopep8 (both are available through pip). Other things (like having CamelCase class names) they won't do (as it could obviously cause the code to stop working).
Reply
#5
(Jun-26-2019, 04:17 PM)nilamo Wrote: Anyway, if it works, that's a pretty big accomplishment for something using async. Nice job.
When it comes to other people looking at your code, it helps to have a similar style. For python, we have what's known as pep8: https://www.python.org/dev/peps/pep-0008/

Thanks. I was unaware of pep8. I'll have to keep this in mind for future updates.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020