1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    A World of wonders.
    Rep Power

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Rep Power
    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.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Woodland Hills, Los Angeles County, California, USA
    Rep Power
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    London, England
    Rep Power
    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

IMN logo majestic logo threadwatch logo seochat tools logo