From: Jan E. <ch...@in...> - 2000-10-06 12:27:23
|
Hi all, 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. I'll need to read and write data from/to a socket, and want to do it asynchronously, outside my main event loop. Easiest thing is to have two threads for handling the incoming and outgoing traffic, and have outgoing data put on a synchronized queue and incoming data being added to the main PySDL event loop using: events_add( event_new(USEREVENT) ) My main thread would then know that something was received. Ok, so far so good. Apparently PySDL *is* htreadsafe, as the documentation states: "The thread management in the SDL library is covered in the core Python language, so there is no thread subsystem in pySDL." This makes me believe that I can from any thread add events to the queue, especially as I haven't found any method for locking PySDL or the event queue. Or am I wrong here? 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. How do you others handle these issues in PySDL and Python? I'm a beginner at both, so all ideas/hints/caveats etc are more than welcome! 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. Regards, Chakie --------------------+-------------------------------------------------------- Jan 'Chakie' Ekholm | Balrog New Media http://www.balrog.fi/ Linux Inside | I'm the blue screen of death, nobody hears your screams |