![]() |
|
[Python] A simple pastebin written in Python - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] A simple pastebin written in Python (/showthread.php?tid=5482860) Pages: Pages
1
2
|
A simple pastebin written in Python - Fudster - Dec 3, 2016 I made a simple pastebin. You can view and install it here Its released under the MIT License Feedback is welcome, from both a coding and user standpoint, Coding changes, feature requests etc. * - Ensky - Dec 3, 2016 Just checked it, it's pretty damn cool to say the least. I've encountered a bug however: The "paste" only contains the first character of any data I've inputted. * - Fudster - Dec 3, 2016 (Dec 3, 2016 02:44 AM)Ensky_ Wrote: Just checked it, it's pretty damn cool to say the least. I've encountered a bug however: That...can't be possible. I guess this is what I get for changing code and not testing (It worked before) . Let me look into it. EDIT: Confirmed bug. Let me look into it. Give me a bit. Shouldn't take long. EDIT2: https://github.com/Fudster/python-pastebin/commit/a9540b994d05bfd5cc10abce3fa3c06edc9f8b62 fixed. * - Ensky - Dec 3, 2016 (Dec 3, 2016 02:47 AM)Fudster Wrote: That...can't be possible. Works perfectly, good work man! * - Fudster - Dec 3, 2016 (Dec 3, 2016 02:56 AM)Ensky_ Wrote: Works perfectly, good work man! Thanks. One of my first python scripts. One thing I gotta do is figure out how to allow the pastebin title to be changed (header and footer) I can do a config variable, Yes just haven't figured out the best way to implent it. I will get around to it tomorrow, Its late. Bedtime for me. * - Ensky - Dec 3, 2016 (Dec 3, 2016 02:59 AM)Fudster Wrote: Thanks. One of my first python scripts. Try to add the amount of lines that are in the code, that'd be perfect * - Fudster - Dec 3, 2016 (Dec 3, 2016 03:00 AM)Ensky_ Wrote: Try to add the amount of lines that are in the code, that'd be perfect Huh? You got my lost. I have no idea what oyu are referring to. Examples? * - Ensky - Dec 3, 2016 (Dec 3, 2016 03:03 AM)Fudster Wrote: Huh? You got my lost. I have no idea what oyu are referring to. On the real pastebin, there's line numbers if you paste anything, useful for pasting code. * - Fudster - Dec 3, 2016 (Dec 3, 2016 03:07 AM)Ensky_ Wrote: On the real pastebin, there's line numbers if you paste anything, useful for pasting code. OH, line numbers. I haven't figured that out either. I might be able to run a for loop for each line using \n I was not able to find any JS scripts that actually have numbering on them. * - Goodies - Dec 5, 2016 Pretty simple. No major complaints, honestly, provided you understand that this can only be a very small server. It'd be perfect for hosting personal pastes for you and your coworkers, but should never go beyond that. It's certainly not scalable for two main reasons: ~ You're using Flask, which is definitely not designed to be for large applications ~ You're synchronously using a database (which is a definite no-no in writing servers). You would have substantially better and more scalable performance if you use the aiohttp.web module (which boasts of a Flask-like API) for hosting the site and something like aioodbc to asynchronously query the database. * - Fudster - Dec 6, 2016 (Dec 5, 2016 02:07 AM)Goodies Wrote: Pretty simple. No major complaints, honestly, provided you understand that this can only be a very small server. It'd be perfect for hosting personal pastes for you and your coworkers, but should never go beyond that. Thanks for the feedback. I dont plan making it a huge site. But since you mentioned it I will look into it and make a new version of the pastebin. Just for learning purposes. * - Blackjack - Dec 7, 2016 (Dec 5, 2016 02:07 AM)Goodies Wrote: Pretty simple. No major complaints, honestly, provided you understand that this can only be a very small server. It'd be perfect for hosting personal pastes for you and your coworkers, but should never go beyond that. I know several large sites that use Flask with no problems - no idea what you're talking about. * - Fudster - Dec 7, 2016 (Dec 7, 2016 05:00 AM)Yani Wrote: I have no experience with Python, but I do have a few points. I did the 1st and 3rd one. Why should I make the VARCHARs? * - Goodies - Dec 7, 2016 (Dec 7, 2016 04:47 AM)Blackjack Wrote: I know several large sites that use Flask with no problems - no idea what you're talking about. MOST large sites that I've seen with Python as their back-end use Django as their main web app framework and Flask is used as some kind of an API or smaller, supplementary application. Don't take my word for it, though. Take a look at the actual Design Decisions in Flask on their official documentation.
In other words, it has a lot of overhead for thread creation and TLS. Anyone who uses Flask for large-scale applications almost certainly (and absolutely should) follow their advice on Becoming Big which is also on their official documentation. If you actually want to test it yourself, it's trivially easy. I'm not sure if you have Pycharm Professional, but I'd highly recommend it, particularly for performance testing. Anyways, I wrote a quick server that simulates being on the internet (as opposed to running on localhost) and performing a time-consuming, CPU-bound task such as database queries by sleeping for a quarter of a second on each request. Simple Flask Server (Click to View) And a simple async client using aiohttp and a semaphore to prevent more than just 15 concurrent clients. Async HTTP Client Example (Click to View) With just 40 URLs allowing no more than 20 concurrent clients (which is fairly small in size). I get performance like this: Code Querying 40 URLs...Compare that vs the exact same thing done with aiohttp. Each request is asynchronously handled on a single thread with non-blocking sockets, and sleeps asynchronously, too: Simple aiohttp server. (Click to View) Look at the difference in the output: Code Querying 40 URLs...Every request gets responded to in the correct amount of time because of its asynchronous nature. To be quite honest, I wouldn't completely trust aiohttp to handle tens of thousands of users, particulraly because it doesn't have a template engine and is event driven but I damn sure wouldn't trust flask to do it, either. Flask is good for API's as it handles JSON very well, but anything with serious database usage would need to be asynchronous for me to consider it. * - Fudster - Dec 7, 2016 (Dec 7, 2016 07:50 PM)Yani Wrote: It's better practice. Hm. Okay do I have to set a size? (Dec 7, 2016 08:06 PM)Goodies Wrote: Every request gets responded to in the correct amount of time because of its asynchronous nature. To be quite honest, I wouldn't completely trust aiohttp to handle tens of thousands of users, particulraly because it doesn't have a template engine and is event driven but I damn sure wouldn't trust flask to do it, either. Flask is good for API's as it handles JSON very well, but anything with serious database usage would need to be asynchronous for me to consider it. Well like I said. I might look into it. But I am not expecting huge usage on this script. Maybe personal and small IRC channels. (under 1,000 users) I am doing this mostly for learning. I am about to move to a deal or no deal game soon. |