socket.error: [Errno 9] Bad file descriptor

3,080 views
Skip to first unread message

Jan-Heiner Dreschhoff

unread,
Jun 16, 2009, 9:43:55 AM6/16/09
to wxPytho...@googlegroups.com
hi everyone,
i am trying to write a small chat, to get to know mutlithreading and sockets, but i keep getting this exception, and i have no idea how to deal with it.
can somebody help me out? the function that is giving me trouble is below

def listen():
    global s
    global lock
    global frm
    data = ""
    while True:
        data = s.recv(1024)
        lock.acquire()
        frm.output.AppendText("server: "+data +"\n")
        frm.output.Refresh()
        lock.release()
        if frm.killflag:
            thread.exit_thread()

    data = s.recv(1024)
  File "E:\Program files\python\lib\socket.py", line 165, in _dummy
    raise error(EBADF, 'Bad file descriptor')
socket.error: [Errno 9] Bad file descriptor
Unhandled exception in thread started by <function send at 0x0000000003652898>

also: how can i write something like this without using global variables?

hendryk

unread,
Jun 16, 2009, 10:18:52 AM6/16/09
to wxPython-users
crap, i just noticed, i didn't mark the end of the code. it ends with
thread.exit_thread()

after that its the compiler output.

thanks for your help

On Jun 16, 3:43 pm, Jan-Heiner Dreschhoff <hdreschh...@gmail.com>
wrote:

Mike Driscoll

unread,
Jun 16, 2009, 1:51:00 PM6/16/09
to wxPython-users
Hi,

On Jun 16, 8:43 am, Jan-Heiner Dreschhoff <hdreschh...@gmail.com>
wrote:
So, what did this have to do with wxPython? If you do use threads in
wx, you'll want to read this wiki page:

http://wiki.wxpython.org/LongRunningTasks

It explains various ways to make threading work and keep it mostly
painless. There are a couple of examples in the demo too.

- Mike

hendryk

unread,
Jun 16, 2009, 5:13:21 PM6/16/09
to wxPython-users
sorry, about that. i forgot about the wx part...was coding a gui and
needed more threads.
discard my inquirey

Robin Dunn

unread,
Jun 17, 2009, 4:25:55 PM6/17/09
to wxPytho...@googlegroups.com

This is OT for this group, but has the socket been connect()ed or
accept()ed?

>
> also: how can i write something like this without using global variables?

One way would be to pass the values as parameters to the function.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Josiah Carlson

unread,
Jun 19, 2009, 11:26:03 AM6/19/09
to wxPytho...@googlegroups.com
Here's an example using async sockets and putting the socket handling
code in the GUI thread, or in a secondary thread:
http://wiki.wxpython.org/AsynchronousSockets

- Josiah
Reply all
Reply to author
Forward
0 new messages