From: Pete S. <pe...@sh...> - 2000-10-06 14:42:21
|
> I was wondering wether the PySDL library is thread safe, > especially the event mechanism. I'm new to threading in > Python (threads in C are familiar), so I may be asking > stupid things here. hi jan. most of the things you're asking about largely depend on how the SDL library handles things. on many platforms (perhaps all) the event handling is thread safe. in fact on some (like X11) the event handling is already handled in a separate thread. as far as handling threads, you'll find pysdl does not support the SDL threading routines. this is because python already comes with great crossplatform threading. (also with it's own semaphores/mutexes/locks). your best bet is to peek at the 'Threading' module http://www.python.org/doc/current/lib/module-threading.html python is also very thread-safe, just make sure it is configured with --threads-enable. (some platform binaries do not come with threads enabled) > Another thing that I was wondering about was that the USEREVENTs > that are created seem to make it impossible for me to attach own > data to them? Ideally I'd like to send the received data along > with the new USEREVENT I'm creating, which would make it really > easy for the main thread to handle. > > An alternative is to just add USEREVENTs and now data. The main > thread would then when it receives one of them check a separate > synchronized queue of incoming data. because the event objects are written as C extensions, it is not easy to modify them much from the python side. your idea for a global user-data queue sounds like the best idea for now. > As a side > not I must say that it is real fun to develop using PySDL. It is big > complete enough to let me do anything I need while still being small > enough to not get in the way of doing stuff. yes, this is the beauty of SDL. it handles so much of the gruntwork, but is nice and thin. i believe you're out pioneering with pysdl and threads. i haven't seen any code doing it so far, and am interested in seeing with what you come up with. just a note here, you might have good results with the 'select' module. this works on windows and unix. it allows you to do asynchronous networking on a single thread. it even works well with multiple sockets. i've never looked into it too far, but i've heard good things about it. anyways if the threading gets too tricky, it might be a good alternative. good luck with everything |