Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is python a serious option for concurrent programming

just considering starting to learning python but I have one concern before I invest more time. Let me phrase this as a statement followed by a concern for others to comment on as perhaps the assumptions in the statement are invalid:

I have read about GIL and the consensus seems to be if you require concurrent solutions in python your best bet is to fork a new process to avoid GIL.

My concern is that if I have a problem I'd like to split into N*2 pieces across N processors (assume for example I have a single server running a *nix o/s with say 8 cores) I will incur context switching penalties between processes rather than between threads, which is more costly, which will limit performance.

I ask this because other languages are out there that claim to excel in such a scenario and I wonder is python appropriate for this arena.

like image 388
Ben Fitzgerald Avatar asked Jan 27 '10 20:01

Ben Fitzgerald


People also ask

Is Python not suitable for highly concurrent multithreaded applications?

Python doesn't support multi-threading because Python on the Cpython interpreter does not support true multi-core execution via multithreading. However, Python does have a threading library. The GIL does not prevent threading.

Which language is best for concurrent programming?

Java, C# and C++ are three well-known languages with good support for concurrency.

How does Python support concurrent execution?

All threads can share same set of open files, child processes. If one process is blocked, then no other process can execute until the first process is unblocked. While one thread is blocked and waiting, a second thread in the same task can run. Multiple processes without using threads use more resources.

What is concurrency in Python programming?

Concurrency in programming means that multiple computations happen at the same time. For example, you may have multiple Python programs running on your computer. Or you may connect multiple computers via a network (e.g., Ethernet) that work together towards a common objective (e.g., distributed data analytics).

Is concurrent programming hard?

Usually concurrent programming is considered hard because low-level abstractions such as threads and locks are used. While NetBeans uses these to a significant extent, it uses also considerably more high-level concepts such as futures, asynchronous tasks, and STM.

Do Python threads run concurrently?

In fact, a Python process cannot run threads in parallel but it can run them concurrently through context switching during I/O bound operations. This limitation is actually enforced by GIL. The Python Global Interpreter Lock (GIL) prevents threads within the same process to be executed at the same time.


1 Answers

multiprocessing can get around the GIL, but it introduces its own issues such as communication between the processes.

like image 60
Ignacio Vazquez-Abrams Avatar answered Nov 15 '22 07:11

Ignacio Vazquez-Abrams