socket.error: [Errno 9] Bad file descriptor

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?

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:

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?

Hi,

···

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

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?

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

sorry, about that. i forgot about the wx part...was coding a gui and
needed more threads.
discard my inquirey

···

On Jun 16, 7:51 pm, Mike Driscoll <kyoso...@gmail.com> wrote:

Hi,

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

> 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?

So, what did this have to do with wxPython? If you do use threads in
wx, you'll want to read this wiki page:

LongRunningTasks - wxPyWiki

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

- Mike

Jan-Heiner Dreschhoff wrote:

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>

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

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

···

On Tue, Jun 16, 2009 at 6:43 AM, Jan-Heiner Dreschhoff<hdreschhoff@gmail.com> wrote:

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?

>