Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12593

Re: Python thread

From Christian Heimes <lists@cheimes.de>
Subject Re: Python thread
Date 2011-09-02 01:09 +0200
References <j3ov0b$40l$1@dough.gmane.org> <CA85C0D1.88C3%mydevgroup@gmail.com> <0604E20B5F6F2F4784C9C8C71C5DD4DD2F165DD74C@EMARC112VS01.exchad.jpmchase.net> <CAMuTYXgQy1qZrJxRywkvPMxwCHXWnLLmBKNbm+=E2je-NKwAFA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.674.1314918607.27778.python-list@python.org> (permalink)

Show all headers | View raw


Am 02.09.2011 00:46, schrieb Benjamin Kaplan:
> 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).

On Linux threading is implemented with multiple processes. A Linux
pthread is a clone of the process created with the clone(2) syscall. [1]
Each thread has a PID and an entry in the kernel's process table. Tools
like htop can show user land threads as different processes. This may
explain the confusion of the OP. He may have seen multiple Java threads
as different processes.

psutil can list all threads with PIDs. The getpid(2) syscall returns
always the PID of the main process, gettid (only available through
syscall(SYS_gettid)) returns the PID of the current thread.

Christian

[1] http://linux.die.net/man/2/clone

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python thread Christian Heimes <lists@cheimes.de> - 2011-09-02 01:09 +0200

csiph-web