Results 1 to 7 of 7

Thread: python IO freeze

  1. #1
    Join Date
    May 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    python IO freeze

    Is there a way to prevent Python from locking up during an I/O event? I'm using os.popen right now. It is somewhat annoying the have the interface jam while waiting for dhclient to complete.

    Thanks in advance.

  2. #2
    Join Date
    Dec 2006
    Beans
    57

    Re: python IO freeze

    It is all about threading
    -- Guilherme H. Polo Goncalves <ggpolo@gmail.com>

  3. #3
    Join Date
    May 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: python IO freeze

    That was my thought - so I threaded the thing, and it still locks up. I've got a (threaded) daemon using dbus, and whenever I try and read from the popen stream (which has its own thread), it locks the entire thing up, client, daemon and all. I'm kinda new to Python, so chances are I'm doing something wrong. Would you like to see the code?

  4. #4
    Join Date
    Dec 2006
    Beans
    57

    Re: python IO freeze

    what do you mean by "threaded the thing?"

    I don't know if you did the right way.. but, did you create a thread class, added something to it and started ? Show me your revelant code
    -- Guilherme H. Polo Goncalves <ggpolo@gmail.com>

  5. #5
    Join Date
    May 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: python IO freeze

    Like I said, I'm new, and probably did something wrong.


    the [supposedly] threaded class:
    Code:
    	class ConnectThread(threading.Thread):
    		IsConnecting = None
    		
    		def __init__(self,network,wireless,wired,wpa_driver):
    			threading.Thread.__init__(self)
    			self.network = network
    			self.wireless_interface = wireless
    			self.wired_interface = wired
    			self.wpa_driver = wpa_driver
    			self.IsConnecting = False
    			
    		def run(self):
    			self.IsConnecting = True
    			network = self.network
    			
    			#put it down
    			print "interface down..."
    			misc.Run("ifconfig " + self.wireless_interface + " down")
    			#rest of code omitted...
    the code that launches said class
    Code:
    		#triggered by a call via dbus to the daemon
    		self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.wpa_driver)
    		self.ConnectingThread.run()
    		return True

  6. #6
    Join Date
    Dec 2006
    Beans
    57

    Re: python IO freeze

    some points:

    first:
    self.ConnectingThread = self.ConnectThread(network,self.wireless_interface ,self.wired_interface,self.wpa_driver)

    I didnt really understood this, did you create a class inside a class ?

    second:
    You start a thread doing self.ConnectingThread.start() not ConnectingThread.run()

    third:
    you need to use the method join() before that return, join (in python threads) waits for a run method to terminate.

    fourth:
    after seeing what you posted, maybe what you really want is to run the process in background
    -- Guilherme H. Polo Goncalves <ggpolo@gmail.com>

  7. #7
    Join Date
    May 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: python IO freeze

    That fixed it, I was doing .run() instead of .start(). Thanks for your help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •