threads check socket
gagsl-py2 at yahoo.com.ar
Sat Aug 1 02:46:22 CEST 2009
En Fri, 31 Jul 2009 14:42:29 -0300, NighterNet <darkneter at gmail.com>
> On Jul 31, 10:23 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
>> En Fri, 31 Jul 2009 13:35:10 -0300, NighterNet <darkne... at gmail.com>
>> > I been trying to find a way to check the socket is open or not. The
>> > thread are in a group and loop if the sockets are open. If they are
>> > not open delete the thread and remove the group. I need on this.
>> What means an "open socket"? Do you want to detect whether the other
>> closed the connection? In that case reading from the socket returns an
>> empty string.
>> Regarding the "threads in a group", I don't understand what you mean.
>> in general, you don't delete a thread, you just return from its run()
>> method and the thread finishes execution.
> Thread added into the array.
> Well this thread when user leave the
> server want to make sure it not in used so that I can reuse it some
> how or move into another array.
Sorry but it's hard to help if you don't provide enough background. Looks
like you're developing a game server; maybe this story is relevant to you:
Assuming you're talking about TCP: when the client closes the connection
gracefully, you get an empty string '' when reading from the socket. If
the client loses the connection abruptly (the power goes down, the network
is broken, the process is killed...) you get no indication of that. You
may need to implement some mechanism (a PING? query/response, or perhaps
the client must send an "I'm alive!" message once each N minutes; no
answer means it's down and the server closes the connection).
> Need to know the thread speed that need for game server timer to
> control it. Don't want it too fast or slow for the game server.
> fps = 30
> def run(self):
> while True:
> self.gametime += 1
> if self.gametime > 10000000/fps:
> self.gametime = 0;
What's this code used for, apart from sucking lots of CPU power?
More information about the Python-list