Python and multiple user access via super cool fancy website

Chris Warrick kwpolska at gmail.com
Thu Dec 24 15:11:03 EST 2015


On 24 December 2015 at 20:39, Aaron Christensen
<aaron.christensen at gmail.com> wrote:
> Hi all,
>
> I am not sure if this is the correct venue for my question, but I'd like to
> submit my question just in case.  I am not a programmer but I do have an
> incredible interest in it, so please excuse my lack of understanding if my
> question isn't very thorough.
>
> As an example, a website backend is developed using Python.  Users can
> submit their input through the website and PHP (or some other language)

Cut out the middle man! Write your web app in Python, which is much
saner and more modern than PHP ever will be. Write it in Django, or
Flask, or Pyramid, or [insert favorite web framework here].

> transfers the user input from the website fields to a database such as
> MySQL.  There is a main script called main_script.py which extracts the
> user data from MySQL, processes it, stores output in MySQL and sends output
> to the user (via webpage and email).
>
> About main_script.py
> # main_script.py extracts user input from MySQL, processes it, stores
> output in MySQL and send output to user (via webpage and email).
> # Inputs: User personal information such as age, dob, nationality, hobbies,
> and 20 or 30 other fields
> # Output: main_script.py is going to do something with it such as access
> the database and some shelve files or other py scripts. I have no clue what
> it's going to do, but my point is that the processing of the input to
> output will take longer than simply a print('Hello, %r!' %user_name).

Well then, figure it out first.You shouldn’t be using shelve, it’s
really unsafe and error-prone — and you already have a perfectly
serviceable database! (PS. PostgreSQL is better)

> My question:  I am curious to know how Python handles something like this.
> Let's say that there are 10, 20, 50, or even 1000 users accessing the
> website.  They all put in their 20 to 30 pieces of input and are waiting on
> some fancy magic output.  How exactly does that work?  Can multiple users
> access the same script?  Does the Python programmer need to code in a
> manner that supports this?  Are requests to the script handled serially or
> in parallel?

We don’t know how you will structure your application.
If you do the “fancy magic” in your web app, which you should if it
won’t take more than, say, 5 seconds, this will be handled by your
WSGI server (eg. uwsgi), which typically can spawn threads and
processes for your web application. Otherwise, you might need to use
an async framework or a task queue with multiple workers.
It would be better to have some idea of the desired output, though.

There are many Python-based web services out there, eg. YouTube,
Instagram or DISQUS. And they work well under constant load.
-- 
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16



More information about the Python-list mailing list