Question on Threading

Hello,

I'm working on a wxPython socket client that connects to a telnet address and retrieves and send information.
I am able to send information to the server, but I'm not sure how to receive? I tried adding a loop in the main gui
for socket.recv(1024), but that failed miserably.

I was reading that Python Threading would accomplish this, but the help file is vague enough to explain how it works.
I have searched on googles and again there aren't any good tutorials that explains the way this work?

Can someone please explain how this work, or where I can read more about this? Any good Python books that
explains this very well and with some examples? I usually learn by looking at examples scripts, but the examples in
Python or wxPython don't explain what the programs are doing...

PS: Is there an easier approach to accomplishing this, or am I going about it the right way?

Thanks!

Allever wrote:

I'm working on a wxPython socket client that connects to a telnet address and retrieves and send information.
I am able to send information to the server, but I'm not sure how to receive? I tried adding a loop in the main gui
for socket.recv(1024), but that failed miserably.

My suggestion would be to study the source code for asyncore.py and SocketServer.py (both part of the standard Python library) for more info, but basically you need to set up a thread that watches the input for incoming data, then posts it to the wx app.

I've found the least problems involve using select.select() to poll the input; this is how asyncore does it.

To get the data from your thread to the wx app, in V2.5 use wx.CallAfter() to call a method in your app. This integrates it into the wx event queue and thus prevents any nasty race conditions or other conflicts.

PS: Is there an easier approach to accomplishing this, or am I going about it the right way?

More or less the right approach. You just need to hone it down.

Suggestion #1: see above regarding working example code.

Suggestion #2: Forget about wx initially; prototype it as a shell process until you get it working the way you want, then work on integrating it into your wx app.

Suggestion #3: Break it up into bits and get the bits working, then work on integrating them together.

Finally, if you get really *really* stuck I have some code that works in a half-assed way that should nudge you in the right direction. Just don't sue me if it blows up a nuclear plant or something :slight_smile:

... Too much of a good thing is wonderful.