Re: asynchronous comunication, wxPython and threads.

2005-06-22 Thread Zunbeltz Izaola
On Tue, 21 Jun 2005 11:07:35 -0400, Peter Hansen wrote:

 
 Please clarify: what does this mean?  Sending a socket is not a usual 
 way to describe TCP communications.  Do you mean your program _opens_ a 
 socket (like a phone connection) and _sends_ some data, then waits for 
 data to be received from the other end?  Or are you (as it almost 
 sounds) opening and closing sockets repeatedly for each part of the 
 conversation?


Sorry for the lack of clarity. I opened the socket once (i don't know if
itit is important to open inside or outside the comunication thread). And
them send packages and wait for data.

 
 
 I think you are using the term socket where you should be using 
 packet.  A socket is the virtual connection created by TCP.  A packet 
 is either a single blob of data sent by the TCP code in the operating 
 system, or perhaps a single chunk of your own data.
 

Thanks for the vocabulary correction.

 If you are using a single TCP socket to send multiple packets, and you 
 are talking about those packets being sent out of order, it's very 
 unlikely and there must be another explanation.  TCP _is_ reliable, and 
 you will not get data out of order unless you do something to screw 
 things up, for example by creating a race condition by doing 
 multithreaded code incorrectly.
 

I think this is the case (see the post of Toby). I didn't try it out but I
think the problem is that i *do* comunication in both threads.

 
 Some people advise that, but there's really nothing *wrong* with doing 
 this in a second thread, and in fact I do similar things all the time 
 with no ill effects.  While async frameworks _can_ make this easier, 
 they could also make it harder (at least for a while) as you adjust your 
 brain to the new approach.  Furthermore, at least in the case of 
 wxPython and Twisted (on Windows) there can be problems integrating the 
 two loops.  I don't believe the latest Twisted claims to have fully 
 solved the problems involved yet, so you might still be required to have 
 a second thread for the TCP stuff.
 

Yes, i have read that there is problems yet.

 
 I use a non-blocking socket and select() calls in my thread, and 
 communicate with the GUI thread using appropriate Queue objects and 
 calls to PostEvent() (or CallAfter()) on the wx side of things.  It's 
 pretty straightforward, so if you post a small piece of your application 
 which reproduces the problem it shouldn't be hard for someone here to 
 help you fix it.
 

Thanks. First i would check if the problem is what Toby says.

 
 No more so than using threads, unless your problem is caused by the
 threads themselves (as I suggested above) in which case it might be
 easier to just fix the problem.
 
 -Peter

Thank you very much

Zunbeltz

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asynchronous comunication, wxPython and threads.

2005-06-22 Thread Zunbeltz Izaola
On Wed, 22 Jun 2005 09:28:31 -0400, Peter Hansen wrote:


 Almost certainly it is.  It would be simplest to set up a worker thread 
 once, when the GUI thread begins, and simply send requests to it via a 
 Queue.  It can create the socket, connect to the server, communicate, 
 close it down, and go back to waiting all in one place (so to speak... 
 of course this would be several methods all called from a top-level loop 
 in that thread).  No chance of mis-steps.

I corrected the problem. A bit of the comunication was done in the
GUI thread. 

Thanks again for your help.

Zunbeltz


-- 
http://mail.python.org/mailman/listinfo/python-list


asynchronous comunication, wxPython and threads.

2005-06-21 Thread Zunbeltz Izaola
Hi,

I have the following problem.

I'm developing a GUI program (wxPython). This program has to comunicate
(TCP) whit other program that controls a laboratory machine to do a
measurement. I have a dialog box, wiht two buttoms Start measurement and
Stop. Start executes a function that do the measurement in the
following way.

1) My program send a socket.
2) The other program recives it an send confirmation.
3) My program waits for the confirmation and send the next when
confirmation received.

This comunication is done in a new thread not to frezee the GUI.
The problem is that when Stop is done (it kills the thread) some
confirmation sockets are mixed (are not receibed in the correct order
although i use tcp).

I have been told not to do comunication in a new thread; instead, I should
use asyncronus comunication.

My question:

What module should i use, asyncore, asynchat, twisted,(anohter) 
How can i implement this asynchronous comunication and the ability to
stop this long run funciton (the measurement can take hours or days, so
i need a way to stop it)?
Can asynchronous comunication garantee that the confirmation socket will
arrive in the correct order (one after each sended socket)? 

Thanks for your help

Zunbeltz Izaola
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asynchronous comunication, wxPython and threads.

2005-06-21 Thread Zunbeltz Izaola
On Tue, 21 Jun 2005 15:30:41 +0100, Toby Dickenson wrote:

 On Tuesday 21 June 2005 14:22, Zunbeltz Izaola wrote:
 
 
 I guess you are accessing the socket from both your GUI thread and 
 communications thread. Dont do that. An action in the GUI thread should 
 signal the communictions thread, then the communictions thread talks to the 
 socket.
 

I see ..., Could be the problem that the socket is created in the GUI
thread? the function that end the theraded function (abort())
set want_abort = True
This make the Measurement() function to return. The Measurement()
funtion is called by startmeasurement() which is the threaded funciton.
After aborting i execute a function that FinalizeMeasuremnt() that 
does comunication to some adjustament in the machine. Maybe i have to move
this portion to the threaded funtion.


 
 Using non-blocking sockets in the GUI thread may cause the opposite problem 
 to 
 the one that led you to use threads in the first place: a blocking operation 
 in the GUI may freeze the communications. Maybe that isnt a problem for you. 
 If it is, I suggest sticking to two threads.
 

Yes, i think i have to stick to two threads.

 
 If you are talking to only one device, then using blocking sockets is a good 
 approach. However Ive never written an application like this that didnt need 
 to support a second (or third) machine sooner or later, and three 
 communictions threads is starting to get ugly. A framework like Twisted will 
 let you handle many machines in the one thread, but it still makes sense to 
 keep a second one for the GUI.

I didn't get this. What do you do when you have more tham one device; use 
thread or use 
Twisted? Did you use it whit wxPython. I think thereis some problems of 
compatibility.


Thank you very much.

Zunbeltz

-- 
http://mail.python.org/mailman/listinfo/python-list


asyncore and GUI (wxPython)

2005-06-13 Thread Zunbeltz Izaola
Hi,

I have the followin situation.

1) I've a machine controled by a computer programn that can 
comunicate with TCP/IP (server)to recive the request of other
program to knwo what the machine should do. 
2) The other program (client) has a GUI (with wxPython), recives 
data from the machine and should process it (draw and write to file).

In the current situation the comunication is done in a thread. Every 
time data is collected it is pased to the main thread of the GUI, with 
a wxPostEvent. Every stream_socketk sended by the client has its
correspondig answer from the server.  (I log the comunication an 
every received socket is the anser of the sended one)

The problem: when i stop the thread (i don't no why) the answer to 
the last socket don't correspond to the last sended (they mix).


The possible correction? I have been told not to do network connection
in other thread, instead i should use asyncore. I'll be sending sockets
every 0.1 seconds or faster. Will be the main progam freeze in the
asyncore loop, or it will refresh the windows and response to
mouse/keyboard properly? How fast can i be sending sockets without
distourbing the main program; or (it is very likeyly) i am totaly wrong
and i should take another way?

Thanks in advance

Zunbeltz


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: avl tree

2005-06-01 Thread Zunbeltz Izaola
On Tue, 31 May 2005 22:40:19 +0200, Berthold Höllmann wrote:

 You can grab it from 
 
   http://starship.python.net/~bhoel/avl-2.1.0.tar.gz
 

Thanks i will play with it. But i have realize that what i need was
exactly a binary tree. I haven't used tree yet and i don't know if i 
can use the avl instaead an ordinary binary tree.
I have to construct a tree like this

 A

B  C

 A C A B

B C   A B   B C   A C


but i think i can construct a avl using left/right. Am I correct?

Thanks again,

Zunbeltz

 Please report any problems to me. I'll do my best to solve them.
 
 Regards,
 Berthold

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: avl tree

2005-05-31 Thread Zunbeltz Izaola
On Mon, 30 May 2005 21:13:57 +0200, Berthold Höllmann wrote:

 
 I'm afraid you won't be happy with the code. It's very old and likely
 won't compile. We have an inhouse version of this module which
 compiles and run on Sparc solaris (32 Bit) and linux x86 with Python
 up to 2.4. I fixed some warnigs just today for compilation on Linux
 x86_64, it also seems to work on this platform now. Installation is
 setup.py based. I'm quite sure we once sent patches to Sam Rushing,
 but they never made it into his release. I'll try to publish our
 version the next days. 

Thanks. I will be looking forward to the release.

regards,

Zunbeltz

 
 Regards
 Berthold

-- 
http://mail.python.org/mailman/listinfo/python-list


avl tree

2005-05-30 Thread Zunbeltz Izaola
Hi,

I'm trying to install avl module from
http://www.nightmare.com/squirl/python-ext/avl

and i had the following instruction to install

Building:

Unix:
First, cd $(AVL_LIB), then 'make libavl.a'

Then copy AVLmodule.c into your Modules directory.
add a few lines like this to your Python/Modules/Setup file.
---
# avl module
AVL_LIB=/usr/src/other-homes/rushing/python/avl
avl AVLmodule.o -DDEBUG_AVL -I$(AVL_LIB) -L$(AVL_LIB) -lavl
-

I have build livavl.a, but i don't understan where is Python/Modules/Setup
and where goes the AVLModule.c file goes.


Could anyone help me,

Thanks,

Zunbeltz
-- 
http://mail.python.org/mailman/listinfo/python-list


stop a thread safetely

2005-05-13 Thread Zunbeltz Izaola
Hi,

I have a wxPython application that call makes a thread (with threading
module). In some moment i've to stop the thread but i need to finish a 
funtion in the thread before it can stop. How can i achive this?

Thanks in advance

Zunbletz
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stop a thread safetely

2005-05-13 Thread Zunbeltz Izaola
On Fri, 13 May 2005 09:10:13 -0400, Peter Hansen wrote:

 
 How did you intend to stop the thread in a manner which might be unsafe?
 (Hint, unless you're doing something unusual, you can't.)
 

I have a threaded object (Mythread). It checks if want_thread
variable is True to return. The problem is that this object 
execute a function that is a tcp comunication

def Client(self,Request,Answer):
totalsent = 0
while totalsent  608:
sent = self.sock.send(Request.struct2string()[totalsent:])
if sent == 0:
raise RuntimeError, socket broken
totalsent = totalsent + sent

if Request.Codigo != 37:
self.WriteLog(Request,Request)
data = self.sock.recv(608)
Answer.string2struct(data)
if int(Answer.Param[9]) != 37:
self.WriteLog(Answer,Answer)


The Client function send a Request (them write it in a log file),
gets and answer and and write it. The problem is that when i stop
the thread a get somethime the Request writed but not the answer,
as if the funciton Client returns before it ends.

Zunbeltz

 -Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: save an opengl canvas (wxPython)

2004-12-15 Thread Zunbeltz Izaola
Mike C. Fletcher [EMAIL PROTECTED] writes:

 There's sample code in PyOpenGL and OpenGLContext for saving canvases
 to PNG or JPEG formats using PIL.  Saving to Postscript requires
 considerably more work (if you're implying saving as triangles, lines
 and the like).  There is a GPL library which lets you do this, and I
 have an old SWIG wrapper for it sitting around somewhere (I think,
 haven't touched it in years), but even then, it's fairly poor quality
 compared to capturing a bitmap image.
 
 Anyway, the function for reading a buffer is glReadPixels:
 http://pyopengl.sourceforge.net/documentation/manual/glReadPixels.3G.xml
 see the end of that man page for pointers to Python sample code.
 
 Good luck,
 Mike
 

Hi Mike,

Thanks for the answer. I'll check the code. For the moment png or jpeg
is ok, but maybe in the future i'll like to save the image as
postscript to use it with LaTeX font and so on. I've se the gl2ps
library and the last version is 21 September 2004. Can you send me
the SWIG file? I don't know much about swig and it would be easier
to start with a file that has work in same older version.

Thanks again

Zunbeltz



-- 
Zunbeltz Izaola Azkona|  wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila  |
Zientzia eta Teknologia Fakultatea|  Phone: 34946015326
Euskal Herriko Unibertsitatea |   
PK 644|  Fax:   34 944648500
48080 Bilbo (SPAIN)   |
-- 
http://mail.python.org/mailman/listinfo/python-list


save an opengl canvas (wxPython)

2004-12-13 Thread Zunbeltz Izaola

Hi,

I've a drawing made in an OpenGL canvas. I want to save it to a file
(preferibly PostScript format). Somebody knows how to do it?

TIA

Zunbeltz

-- 
Zunbeltz Izaola Azkona|  wmbizazz at lg dot ehu
dotes
Materia Kondentsatuaren Fisika Saila  |
Zientzia eta Teknologia Fakultatea|  Phone: 34946015326
Euskal Herriko Unibertsitatea |   
PK 644|  Fax:   34 944648500
48080 Bilbo (SPAIN)   |
-- 
http://mail.python.org/mailman/listinfo/python-list