[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: mulithreaded server

exarkun

3/11/2008 4:10:00 PM

On Tue, 11 Mar 2008 08:24:54 -0700 (PDT), asit <lipun4u@gmail.com> wrote:
>import socket
>import sys
>import thread
>
>p=1
>PORT=11000
>BUFSIZE=1024
>
>def getData(cSocket):
> global stdoutlock,cSocketlock
> while True:
> cSocketlock.acquire()
> data=cSocket.recv(BUFSIZE)
> if data=='q':
> data='client exited'
> cSocket.close()
> p=0
> cSocketlock.release()
> stdoutlock.acquire()
> stdout.write(data)
> stdoutlock.release()
>
>def sendData(cSocket):
> global stdoutlock,cSocketlock
> while True:
> stdoutlock.acquire()
> data=raw_input('>>')
> cSocketlock.acquire_lock()
> if data=='q':
> stdout.write('server exited')
> stdout.release()
> p=0
> cSocket.close()
> sSocket.send(data)
> sSocketlock.release()

Could it be because `sSocketlock´ here

>
>
>stdout=sys.stdout
>host=''
>sSocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>sSocket.bind((host,PORT,))
>sSocket.listen(1)
>#sSocketlock=thread.allocate_lock()

is never bound since the line above here is commented out?

>stdoutlock=thread.allocate_lock()
>print 'waiting for connection'
>cSocket,addr=sSocket.accept()
>print 'connection from',addr
>cSocketlock=thread.allocate_lock()
>thread.start_new_thread(sendData,(cSocket,))
>thread.start_new_thread(getData,(cSocket,))
>if p==0:
> sSocket.close()
>
>
>
>In the above program, why there is an unhandeled exception ???

Just a guess. You should really include the traceback when you ask a
question like this.

Jean-Paul
3 Answers

asit

3/11/2008 7:17:00 PM

0

On Mar 11, 9:10 pm, Jean-Paul Calderone <exar...@divmod.com> wrote:
> On Tue, 11 Mar 2008 08:24:54 -0700 (PDT), asit <lipu...@gmail.com> wrote:
> >import socket
> >import sys
> >import thread
>
> >p=1
> >PORT=11000
> >BUFSIZE=1024
>
> >def getData(cSocket):
> > global stdoutlock,cSocketlock
> > while True:
> > cSocketlock.acquire()
> > data=cSocket.recv(BUFSIZE)
> > if data=='q':
> > data='client exited'
> > cSocket.close()
> > p=0
> > cSocketlock.release()
> > stdoutlock.acquire()
> > stdout.write(data)
> > stdoutlock.release()
>
> >def sendData(cSocket):
> > global stdoutlock,cSocketlock
> > while True:
> > stdoutlock.acquire()
> > data=raw_input('>>')
> > cSocketlock.acquire_lock()
> > if data=='q':
> > stdout.write('server exited')
> > stdout.release()
> > p=0
> > cSocket.close()
> > sSocket.send(data)
> > sSocketlock.release()
>
> Could it be because `sSocketlock´ here
>
>
>
> >stdout=sys.stdout
> >host=''
> >sSocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> >sSocket.bind((host,PORT,))
> >sSocket.listen(1)
> >#sSocketlock=thread.allocate_lock()
>
> is never bound since the line above here is commented out?
>
> >stdoutlock=thread.allocate_lock()
> >print 'waiting for connection'
> >cSocket,addr=sSocket.accept()
> >print 'connection from',addr
> >cSocketlock=thread.allocate_lock()
> >thread.start_new_thread(sendData,(cSocket,))
> >thread.start_new_thread(getData,(cSocket,))
> >if p==0:
> > sSocket.close()
>
> >In the above program, why there is an unhandeled exception ???
>
> Just a guess. You should really include the traceback when you ask a
> question like this.
>
> Jean-Paul

It's not a traceback error. It's an unhandeled exception..please help

aahz

3/11/2008 7:38:00 PM

0

In article <0e845694-2788-43e2-b88b-86bbbbe3c7c0@e23g2000prf.googlegroups.com>,
asit <lipun4u@gmail.com> wrote:
>On Mar 11, 9:10 pm, Jean-Paul Calderone <exar...@divmod.com> wrote:
>> On Tue, 11 Mar 2008 08:24:54 -0700 (PDT), asit <lipu...@gmail.com> wrote:
>>>
>>>In the above program, why there is an unhandeled exception ???
>>
>> Just a guess. You should really include the traceback when you ask a
>> question like this.
>
>It's not a traceback error. It's an unhandeled exception..please help

http://www.catb.org/~esr/faqs/smart-ques...
--
Aahz (aahz@pythoncraft.com) <*> http://www.python...

"All problems in computer science can be solved by another level of
indirection." --Butler Lampson

Aaron Brady

3/11/2008 7:49:00 PM

0

> > >In the above program, why there is an unhandeled exception ???
>
> > Just a guess. You should really include the traceback when you ask a
> > question like this.
>
> It's not a traceback error. It's an unhandeled exception.

Have a look at this:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/5cbf901...

It gives you a console with several threads running that you send
functions to call to. Then it connects to a socket on one of them,
serving on the other.