LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2014, 02:57 AM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
CPython GIL threading problem.


We work on a linux server. When I type python, the information is as follow:
Code:
Python 2.6.6 (r266:84292, May  1 2012, 13:52:42) 
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
I think this is a CPython version,isn't it?
When I write a threading program, I found some threads would starve.
After some google, I realize there is a thing called GIL(Global Interpreter Lock) in CPython.
If I want to use multithreading in python, What would you suggest? Thanks in advance!

example code that create a thread, and one of the thread would starve in my linux.
Code:
import time
import threading, thread

class thread_reload_config(threading.Thread):
    def run(self):
        while True:
            print("thread to reaload logging config file")
            time.sleep(5)

def main():
    print("enter main function")
    t = thread_reload_config()
    t.start()
    
    while True:
        print("still running")
        time.sleep(3)
if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        exit(0)
 
Old 04-02-2014, 05:08 PM   #2
frostschutz
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 95

Rep: Reputation: 28
Your example code seems to work fine for me, except it doesn't handle keyboard interrupts well at all. You should avoid threading if possible, or if you're serious about it, maybe another language is more appropriate. For example Go uses a lot of concurrency and threading and stuff. But it's very, very different from Python.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ problem multi-threading Mr Tummyfluff Programming 6 12-03-2008 01:06 PM
Problem with gtk_main and multi threading arun.tayal Programming 0 10-15-2008 01:20 AM
Adding cpython to nbpython! amaj1407 Programming 0 10-10-2008 08:17 AM
gil = TCP/IP process consumes a lot of CPU pete83 AIX 1 05-09-2008 02:57 AM
multi threading slower than single threading on dual core. why? nebojsa.andjelkovic Programming 13 01-30-2007 09:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration