thread. question

Christian Heimes lists at cheimes.de
Mon Feb 9 15:02:01 EST 2009


Tim Wintle schrieb:
> Thanks for both replies,
> 
> On Mon, 2009-02-09 at 15:59 +0100, Christian Heimes wrote:
>> You shouldn't use the thread module directly. It's not meant to be used
>> by a user. Please stick to the threading module. You won't notice a
>> slowdown, trust me :)
> I'm aware that thread is being renamed to _thread in python 3.0, but is
> it being depricated or anything like that?
> 
> This is for an app that has been running for quite a long time and it's
> now time for fairly heavy optimisations as load is increasing (Believe
> me, I wouldn't have been looking at the C otherwise) - so I'll see if I
> do notice any effect with threading.

[snip]

> Thanks for the info - I'm very aware of the GIL, but had never looked at
> the implementation before and for some reason thought that python's
> threads were in userspace.
> 
> I'm already using a multiple-process architecture overall, but using
> threads to avoid waiting when handling SQL and TCP.

The module was renamed to _thread to stop people from using it directly.
The extension module is the interface to some low level types and
functions. Especially the usage of thread.start_new_thread is
problematic, since it bypasses Python's high level threading API.

For the rest I have to agree with Jean-Paul. If you need performance
don't use threads! Threads and performance are orthogonal -- sometimes
they are even contradictorily.




More information about the Python-list mailing list