DEV Community

Cover image for Choosing Python for Web Development: Top 16 Pros and Cons

Choosing Python for Web Development: Top 16 Pros and Cons

Django Stars on October 07, 2019

Did you know that Python was named after Monty Python? One of the world’s most popular coding languages, Python was first conceptualized in the la...
Collapse
 
antontsvil profile image
Anton T

Great write up! Could you elaborate on what you mean by Python not having "true" multiprocessor support?

Collapse
 
loki profile image
Loki Le DEV

Python has what is called the "Global Interpreter Lock", you can read more here: docs.python.org/3/c-api/init.html#...

Meaning that when you launch multiple threads in the same python interpreter they are actually locked on one core and can't be really parallelized. For some applications it's not a real issue, when your threads spend most of the time sleeping/waiting for IO for example. But when you need real parallel computing on multiple cores you can't do it with threads.
Python provides the "multiprocessing" module to workaround this, launching code in separate processes. It makes it a bit harder but not impossible to do real multi core parallelization.

Collapse
 
antontsvil profile image
Anton T

Thanks for your explanation! So if I'm understanding correctly the only real way to do parallel processing is to have multiple python processes separate from each other. But that means the data used by each process is sort of isolated, right?

Thread Thread
 
loki profile image
Loki Le DEV

Yes, the multiprocessing module provides some tools to exchange this data: docs.python.org/2/library/multipro... but your data needs to be easily serializable which is not always the case.

Thread Thread
 
rhymes profile image
rhymes

@antontsvil , I personally think the article is a bit misleading becuase it mixes different details under umbrella terms but @loki already explained what's going on in Python :)

Collapse
 
rdil profile image
Reece Dunham

I'm pretty sure that the meaning of this is that Python doesn't handle this stuff well - dealing with it is a pain. I would love Python to the end of time if it just had multithreading that worked.

Collapse
 
rhymes profile image
rhymes • Edited

A couple of notes right from the start:

Python was opensource since the first public release, not since version 2.0, its first public version was in February 1991.

Instagram has around a billion daily active users, not 4 million.

It doesn’t take much effort to write and maintain asynchronous code using Python since there are no deadlocks or research contention or any other confusing issues

This is misleading. Async programming is hard, please don't go around tell people that concurrency is easy eheh. asyncio is a great step forward (asyncore and asynchat in Python 2 were truly horrible) but it's common knowledge that it is not that easy. Which is also the reason they are wrappers on top of it and different approaches like trio to try to make programmers lives easier.

Python does support multiprocessing, although it might not be as flexible or convenient as other languages. This can create certain limitations when you’re writing the code.

I think this sentence is detrimental for a beginner. There's no explanation, just a "yeah you can do it but it's not great". In strict terms Python has multiprocessing support that can have an easy to use interface, I even wrote an article about here on DEV: How to make Python code concurrent with 3 lines.

I'm sure you're referring to something specific but this sentence instills doubt in people without actually having an explanation for it.

I don't think you meant multithreading instead of multiprocessing, but maybe you did?

There's a difference between "multiprocessing" and "support of multiple processors" (which Python always has through multiprocessing but doesn't have in memory bound situations in multithreading due to the GIL). From docs.python.org/3/library/multipro... The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both Unix and Windows.

Another thing you should be aware of when considering Python for your project is that concurrency and parallelism aren’t intended for elegant use in Python. Because of that, the design might not look as sophisticated as you’d like.

I think assertions like this should be clarified in overview articles aimed at beginners. As a seasoned developer I have a likely idea of what you mean (the fact that concurrency is not a language construct but it's done through libraries?), but I'm honestly not even sure about that.

Collapse
 
kateryna_pakhomova profile image
Kateryna Pakhomova

I really enjoyed reading your article. I’d agree on most points there and also learned a few interesting new things. BTW, our team have also written on a similar topic. I think your readers might benefit from checking it out: softformance.com/blog/python-progr...

Collapse
 
socr102 profile image
Eric

Hello I am beginner of python
Your writing is Great for me
I am going to make the e-commerece site using the python/Django
what do you think about its?
The Django is suitable to make the shoping site?
If you have some comment, please let me know

Collapse
 
emizex profile image
layefa Amakubukuro

Very informative for a newbie