blocking socket dilemma

Steve Holden sholden at holdenweb.com
Wed Sep 11 04:56:18 EDT 2002


"Gumuz" <gumuz at looze.net> wrote ...
> Hi all,
>
> I am a little bit stuck with my design (again!).
>
> I have this server class, which creates a session object for every
accepted
> incoming connection. The session object has a RequestHandler function
which
> is then run in a new thread.
>
> all fine, but...
>
> This RequestHandler function actually does a infinite loop. The loop wil
> receive data and take some action and it will send data which is piled up
in
> this session's queue. The problem that i'm having is that the loop will
hang
> on socket.recv if the client is not sending anything. Ofcourse this is
very
> obvious and logical, but i can't think of another way of constructing my
> design, so that this problem doesn't occur.
>
> I hope i've made my problem clear to you guys.
>

You may be ready to migrate to an asyncore-based solution. In such
situations it's usually easier to adopt a more flexible program structure.
Asyncore/asynchat my be just what you need. They certainly put a muc more
direct emphasis on the buffering required in a TCP session.

The SocketServer-based modules are sufficient for simple interactions, but
don't hack it when a "Request" becomes a series of interactions over the
same socket, for example like a Telnet session.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list