stefan ring iyvisotechat company work last couple years created application server use customer projects embeds python project code written python quite resourcehungry several gb ram mysql databases 50100gb course multithreaded least originally hoped make utilize multiple processor cores know doesnt sit well python application runs heavy background calculations time python service multiple gui clients time also using python problem single background thread would increase response time client threads factor 10 usually led add dirty hack python core make switch threads frequently hack greatly improved response time gui clients also slowed background threads quite bit top would often show significantly less cpu usage 80 instead usual 100 problem thread switching python global semaphore used gil regularly released immediately reacquired unfortunately time leads thread winning race semaphore thus wait time threads dirty patch intervened nanosleep short amount time used 1000 nsecs created better scheduling scheme written small test program nicely mimics python statistics call scheduling algorithm roundrobin semaphore threads run less roundrobin fashion actually semaphore fifo semantics implementation problem roundrobin semaphore __thread variable use want change signature enter leave methods cpython replaced threadlocal allocation additional field pythreadstate patch cpython already created bit involved simple nanosleep hack consequently polished yet portable rest python core show results test program compares three scheduling mechanisms standard python dirty hack new roundrobin semaphore also show test program containing three implementations nicely encapsulated program run quadcore xeon 186 ghz fedora 5 x86_64 first three lines output including name algorithm selfexplanatory fourth fifth show distribution wait times individual threads ideal distribution would everything number threads 2 case zero everywhere else see roundrobin semaphore pretty close also high thread switching frequency could lower pythons checkinterval jury still actual value likely something 1000 10000 post python patch enough interest thanks attention tue 05 aug 2008 112038 0100 pythondev improved thread switching