Python thread

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Sep 2 00:46:32 CEST 2011


On Thu, Sep 1, 2011 at 6:21 PM, Prasad, Ramit <ramit.prasad at jpmorgan.com> wrote:
>>So what exactly does threading module do, if it doesn't create a subprocess.
>>Does each thread have its own stack and PC.
>>What advantage would a threading module provide over sequential execution.
>
> I believe it merely simulates multiple processes through scheduling (like the CPU).
>
> >From http://docs.python.org/library/threading.html: CPython implementation detail: Due to the Global Interpreter Lock, in CPython only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). If you want your application to make better of use of the computational resources of multi-core machines, you are advised to use multiprocessing. However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.
>
> Ramit

Threading is an OS-level construct to allow concurrency within a
single process (and address space). Threads are never supposed to be
separate processes (they aren't at the C-level, so I don't know what
Java is doing here). CPython code has a global interpreter lock which
prevents two threads from running Python code at the same time, but
they're still useful for asynchronous operations. For example, one
thread can be waiting for user input while another thread continues to
process data. Other Python implementations such as Jython and
IronPython don't have a global interpreter lock so threads can run
concurrently (and on different cores in a multi-core machine).

> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list