Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Miles Kaufmann" wrote: > On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: > > > A can is like a pickle, in that it is a string, but anything > > can be canned. > > Unlike a pickle, a can cannot leave the process, though, > > unless the object it points to lives in shared memory. > > > > If

Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Scott David Daniels" wrote: > I can think of use cases for can, and from that use an alternate > construct. The use case is passing a reference out over a wire > (TCP port?) that will be used later. This will work, provided the thing is still alive and in the same place when the can eventuall

Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Hendrik van Rooyen
"Gabriel Genellina" wrote: > From your description of the problem, it seems you are acting upon >messages received from a serial port. You have to process the message >*before* the next one arrives -- but you gain nothing doing that much >faster. In other words, even with a blazingly fast p

Re: Winter Madness - Passing Python objects as Strings

2009-06-06 Thread Miles Kaufmann
On Jun 4, 2009, at 3:25 AM, Hendrik van Rooyen wrote: A can is like a pickle, in that it is a string, but anything can be canned. Unlike a pickle, a can cannot leave the process, though, unless the object it points to lives in shared memory. If you have any interest, contact me and I will send

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Gabriel Genellina
En Fri, 05 Jun 2009 12:33:04 -0300, Hendrik van Rooyen escribió: "Gabriel Genellina" wrote: But if you already have a queue, you may put other objects there (instead of "canning" them). Testing the object type with isinstance(msg, str) is pretty fast, and if you bind locally those names I

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Scott David Daniels
Hendrik van Rooyen wrote: "Gabriel Genellina" wrote: Ah... I had the same impression as Mr. Reedy, that you were directly reading from a socket and processing right there, so you *had* to use strings for everything. not "had to" - "chose to" - to keep the most used path as short as I cou

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
"Nigel Rantor" wrote: > Well, why not have a look at Gabriel's response. I have, and have responded at some length, further explaining what I am doing, and why. > That seems like a much more portable way of doing it if nothing else. There is nothing portable in what I am doing - it is aimed a

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
"Gabriel Genellina" wrote: >Ah... I had the same impression as Mr. Reedy, that you were directly >reading from a socket and processing right there, so you *had* to use >strings for everything. not "had to" - "chose to" - to keep the most used path as short as I could. > >But if you already

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Nigel Rantor
Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> It just smells to me that you've created this elaborate and brittle hack >> to work around the fact that you couldn't think of any other way of >> getting the thread to change it's behaviour whilst waiting on input. > > I am beginning to

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Gabriel Genellina
En Fri, 05 Jun 2009 07:00:24 -0300, Hendrik van Rooyen escribió: "Terry Reedy" wrote: You have multiple threads within a long running process. One thread repeatedly reads a socket. Yes and it puts what it finds on a queue. - it is a pre defined simple comma delimited record. You w

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
"Terry Reedy" wrote: > If I understand correctly, your problem and solution was this: > > You have multiple threads within a long running process. One thread > repeatedly reads a socket. Yes and it puts what it finds on a queue. - it is a pre defined simple comma delimited record. > You wan

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
"Jean-Paul Calderone" wrote: > So, do you mind sharing your current problem? Maybe then it'll make more > sense why one might want to do this. Please see my reply to Skip that came in and was answered by email. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
"Nigel Rantor" wrote: > It just smells to me that you've created this elaborate and brittle hack > to work around the fact that you couldn't think of any other way of > getting the thread to change it's behaviour whilst waiting on input. I am beginning to think that you are a troll, as all y

Re: Winter Madness - Passing Python objects as Strings

2009-06-05 Thread Hendrik van Rooyen
wrote: > Got some use cases? plural cases - no. I did it for the reason already described. to elucidate, the code looks something like this: rec = input_q.get() # <=== this has its origen in a socket, as a netstring. reclist = rec.split(',') if reclist[0] == 'A': do something with the ou

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Nigel Rantor
Hendrik van Rooyen wrote: It is not something that would find common use - in fact, I have never, until I started struggling with my current problem, ever even considered the possibility of converting a pointer to a string and back to a pointer again, and I would be surprised if anybody else on

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Terry Reedy
Hendrik van Rooyen wrote: I can see that my explanation passes you by completely. I said, in my original post, that a can could not leave a process. A can is exactly the same as a C pointer, only its value has been converted to a string, so that you can pass it "in band" as part of a string. Th

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread skip
Hendrik> A can is like a pickle, in that it is a string, but anything Hendrik> can be canned. Unlike a pickle, a can cannot leave the Hendrik> process, though, unless the object it points to lives in shared Hendrik> memory. Got some use cases? Thx, -- Skip Montanaro - s...@pob

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Jean-Paul Calderone
On Thu, 4 Jun 2009 16:49:42 +0200, Hendrik van Rooyen wrote: [snip] It is not something that would find common use - in fact, I have never, until I started struggling with my current problem, ever even considered the possibility of converting a pointer to a string and back to a pointer again,

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Hendrik van Rooyen
"Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > "Nigel Rantor" wrote: > > > >> Hendrik van Rooyen wrote: > >>> If you have any interest, contact me and I will > >>> send you the source. > >> Maybe you could tell people what the point is... > > > > Well its a long story, but you did ask.

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Nigel Rantor
Hendrik van Rooyen wrote: > "Nigel Rantor" wrote: > >> Hendrik van Rooyen wrote: >>> If you have any interest, contact me and I will >>> send you the source. >> Maybe you could tell people what the point is... > > Well its a long story, but you did ask... [snip] Maybe I should have said "why

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Hendrik van Rooyen
"Nigel Rantor" wrote: > Hendrik van Rooyen wrote: > > > > If you have any interest, contact me and I will > > send you the source. > > Maybe you could tell people what the point is... Well its a long story, but you did ask... I am working on an i/o system, running in an ebox - it is basically

Re: Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Nigel Rantor
Hendrik van Rooyen wrote: > > If you have any interest, contact me and I will > send you the source. Maybe you could tell people what the point is... n -- http://mail.python.org/mailman/listinfo/python-list

Winter Madness - Passing Python objects as Strings

2009-06-04 Thread Hendrik van Rooyen
When the days get colder and the nights longer, then evil things are hatched. A can is like a pickle, in that it is a string, but anything can be canned. Unlike a pickle, a can cannot leave the process, though, unless the object it points to lives in shared memory. Here is the output of a test se