[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] sockets and events
> Another method is to use a separate thread for the socket handling, and
> somehow have that thread in a safe manner pygame.event.post() USEREVENT:s,
> or using some other mean handle the event.
>
This seems the most appealing option, especially if I can just start up a
simple thread and then forget about it.
So, how do I do threads? Would something like this work :
# assuming there is a socket already make called sock
import select
import thread
SOCKETEVENT = USEREVENT + 0
def socket_has_data_thread(sock):
event = pygame.event.Event(SOCKETEVENT, {'socket':sock})
while 1:
r, w, x = select.select([sock], [], [])
pygame.event.post(event)
thread.start_new_thread(socket_has_data_thread, (sock,))
Also, is it ok to just keep using the same event over and over again?
Thanks
Doug Partridge
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org