1

I'm doing some program in python and i'm having a very strange behavior when I call socket.rcvfrom inside a thread. This is what I'm doing:

def start(self):
    try:
        thread.start_new_thread(self.msgHandler , ())
    except:
        print "Error: unable to start thread"

...

def msgHandler(self):
    while True:
        try:
            data = self.sock.recv(1024)
            print data
        except socket.timeout:
            continue

What is happening is that when I send one message to that socket the thread will not print the data received, it gets stuck there. If I press ctrl+c to kill the process the message content will be shown on screen.

[EDIT] Now I know it is related with gtk.main() witch I am also using.

Paradela
  • 170
  • 6
  • Read the answer to [this question](http://stackoverflow.com/questions/8826523/gtk-main-and-unix-sockets). That should give you an idea of what is happening and the possible solutions. If you're using pyGTK it is probably best to use the mechanisms that it provides for IO, i.e. [IO Channels](https://wiki.gnome.org/Projects/PyGTK/WhatsNew28#IO_Channels). – Roland Smith Nov 24 '13 at 22:13
  • Thank you! With your answer made some more research, and I've found out when using pygtk it will block all your threads unless you call gtk.gdk.threads_init(). Thank you again! – Paradela Nov 24 '13 at 22:57

0 Answers0