June 13th, 2004, 08:42 PM
Select( ) Vs Thread( )
What would you rather use? cause right now im using select to run a while loop in gui program.. and every things runs smothly.. but.. i always get people asking.. "Why are you using select?" or "Why are you using thread" and i want to know what the users here think, as i feel better getting an answer here ( my home ) then any other place, i read about select.. and read a bit about thread and.. i think that select is a good way to go
June 13th, 2004, 09:40 PM
Using threads will add extra complexity to your script. You will have to think about race conditions and the way in which you're going to share data in between threads.
June 14th, 2004, 12:50 AM
Got to remember that adding threads to a Python program to try speeding it up, does not always work. Reason: Python has a Global Interpreter Lock (GIL) that is set every time you try to access a python object and only the thread that holds the lock can access the object. In order for other threads to get some access to the GIL, the interpreter releases the lock every sys.setcheckinterval bytecodes (default = 10 bytecoee instructions) or if the thread blocks for an I/O operation. This way, another thread can acquire the lock and continue.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
June 14th, 2004, 02:46 AM
It depends what your program is doing.
If you are reading from a socket then select is a viable solution - look at the asyncore library for a high level wrapper to it. However using select on files and pipes will only work on UNIX systems, so will not be portable to Windows. This may or may not be a problem for you.
There will probably be times when you want concurrent processing that does not do IO at all, then select will be useless and you will have to use threads.
Dave - The Developers' Coach