Re: Writing a thread-safe class

2009-09-14 Thread MRAB
News123 wrote: So what's recommended way for multicore machines? Threads will probably only accelerate if the used C libraries are releasing the GIL, right? What's for example about PIL (Python Imaging library)? Assuming, that the C library calls don't releas the GIL Shoud I directly use us

Re: Writing a thread-safe class

2009-09-14 Thread News123
So what's recommended way for multicore machines? Threads will probably only accelerate if the used C libraries are releasing the GIL, right? What's for example about PIL (Python Imaging library)? Assuming, that the C library calls don't releas the GIL Shoud I directly use use fork() and some

Re: Writing a thread-safe class

2009-09-12 Thread sturlamolden
On 12 Sep, 15:54, Timothy Madden wrote: > I find that hard to believe, but I will look into it. Carl Banks is correct. There is a mutex called "the global interpreter lock" that takes care of this. You can have multiple threads running, but access to the Python interpreter is serialized. --

Re: Writing a thread-safe class

2009-09-12 Thread Timothy Madden
Carl Banks wrote: [...] You are not correct. Dictionary operation (like getting and setting items) are atomic and limited to one thread at a time, thus thread- safe. > (In fact, in CPython only one thread can execute Python code at a time, in most cases. This is called the Global Interpreter

Re: Writing a thread-safe class

2009-09-11 Thread Carl Banks
On Sep 11, 4:26 pm, Timothy Madden wrote: > Hello > > I would like to write a class with methods that can be accessed by many > threads at the same time. > > For this I have a lock attribute in my class obtained with > threading.Lock(), in the constructor, and every method begins by > acquiring th

Writing a thread-safe class

2009-09-11 Thread Timothy Madden
Hello I would like to write a class with methods that can be accessed by many threads at the same time. For this I have a lock attribute in my class obtained with threading.Lock(), in the constructor, and every method begins by acquiring the lock and ends by releasing it My problem is that