Determine size of string in bytes

2008-03-27 Thread breal
Forgive me for this question which is most likely stupid...

How do I determine the number of bytes a string takes up?  I have a
soap server that is returning a serialized string.  It seems that when
the string goes over 65978 characters it does not return to the soap
client.  Instead I get an error:
error: (35, 'Resource temporarily unavailable')

This makes me think the problem exists on the soap client side with
some sort of max return length.  If I knew how many bytes the 65978
character string was, then I could try to up this value.

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


Re: Determine size of string in bytes

2008-03-27 Thread breal
On Mar 27, 2:10 pm, John Machin [EMAIL PROTECTED] wrote:
 On Mar 28, 6:45 am, breal [EMAIL PROTECTED] wrote:

  Forgive me for this question which is most likely stupid...

 The contents of your question are not stupid. The subject however does
 invite a stupid answer like: len(the_string).

 Disclaimer: I know nothing about SOAP except that it's usually
 capitalised :-) Now read on:

  How do I determine the number of bytes a string takes up?  I have a
  soap server that is returning a serialized string.

 Serialised how? UTF-8?


Yes.  I meant to include that.  I did not understand that len()
returned the actual byte length of a UTF-8 encoded string.

   It seems that when
  the string goes over 65978 characters it does not return to the soap
  client.

 Why does it seem so? How did you arrive at such a precise limit?


I actually just wrote a test that would call a function on the SOAP
server (SOAPpy) that would increase or decrease the test length based
on the previous result until it found x, x+1 where x characters didn't
fail, but x+1 did.  x ended up being 65978.  The string I happen to be
encoding in this case has all ascii characters so it is the same for
both encodings.


   Instead I get an error:
  error: (35, 'Resource temporarily unavailable')

 Is this error from the client or the server? Any error or logfile
 record from the other side?


This is an error on the server.  The client is actually written in
PHP.

There is no log file, but there is a traceback...
Traceback (most recent call last):
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py, line 464, in process_request_thread
self.finish_request(request, client_address)
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py, line 254, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/SocketServer.py, line 522, in __init__
self.handle()
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/BaseHTTPServer.py, line 316, in handle
self.handle_one_request()
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/BaseHTTPServer.py, line 310, in handle_one_request
method()
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/SOAPpy/Server.py, line 545, in do_POST
self.wfile.write(resp)
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/socket.py, line 262, in write
self.flush()
  File /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/socket.py, line 249, in flush
self._sock.sendall(buffer)
error: (35, 'Resource temporarily unavailable')




 Is there anything in the documentation about maximum sizes?



I googled my brains out looking for anything about maximum size both
on the Python SOAP server, and the PHP SOAP client.


  This makes me think the problem exists on the soap client side with
  some sort of max return length.

 Think? Can't you verify this by inspecting the source?


I haven't inspected the source, but I have inspected the
documentation.  No luck in finding anything about it.  I suppose I
could download the client source and see what I can see.

  If I knew how many bytes the 65978
  character string was, then I could try to up this value.

 How do you know the string is 65978 characters? If you are debugging
 the server, can't you do len(serialise(the_65978_char_string))?

 65978? Are you sure? Looks suspiciously close to 65535 aka 0x aka
 (2 ** 16 - 1 ) to me.

 If you have the server, you presumably have the source code for both
 client and server. Some options for you:

 (1) Look at the traceback(s), look at the source code, nut it out for
 yourself. If there is some kind of max other than an implicit 16-bit
 limitation in the client code, it shouldn't be too hard to find.

 (2) Post the traceback(s) here, along with other details that might be
 useful, like what SOAP server s/w you are using, what version of
 Python, what platform.


See traceback above.
SOAPpy
Python 2.5
OSX Server


Thanks for the response John.

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


Handling locked db tables...

2008-02-20 Thread breal
I have a db table that holds a list of ports.  There is a column
in_use that is used as a flag for whether the port is currently in
use.  When choosing a port the table is read and the first available
port with in_use = 0 is used, updated to in_use = 1, used, then
updated to in_use = 0.  I am using MySQLdb and want to make sure I am
locking the table when doing reads, writes, updates since there will
be several instances of my program looking for available ports
simultaneously.

When I run a lock table mytable read I can do all of my
transactions.  But, when another cursor then tries to do the read I
get an error unless the first process has been completed... unlocking
the tables.  How is this handled generally?

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


Re: Handling locked db tables...

2008-02-20 Thread breal
On Feb 20, 8:05 am, M.-A. Lemburg [EMAIL PROTECTED] wrote:
 On 2008-02-20 16:24, breal wrote:

  I have a db table that holds a list of ports.  There is a column
  in_use that is used as a flag for whether the port is currently in
  use.  When choosing a port the table is read and the first available
  port with in_use = 0 is used, updated to in_use = 1, used, then
  updated to in_use = 0.  I am using MySQLdb and want to make sure I am
  locking the table when doing reads, writes, updates since there will
  be several instances of my program looking for available ports
  simultaneously.

  When I run a lock table mytable read I can do all of my
  transactions.  But, when another cursor then tries to do the read I
  get an error unless the first process has been completed... unlocking
  the tables.  How is this handled generally?

 This is normal database locking behavior. If you do an update to
 a table from one process, the updated row is locked until the
 transaction is committed.

 If another process wants to access that row (even if only indirectly,
 e.g. a select that does a query which includes the data from the locked
 row), that process reports a database lock or times out until the
 lock is removed by the first process.

 The reason is simple: you don't want the second process to report
 wrong data, since there's still a chance the first process might
 roll back the transaction.

 Most modern database allow row-level locking. I'm not sure whether
 MySQL supports this. SQLite, for example, only support table locking.

 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Feb 20 2008) 
 Python/Zope Consulting and Support ...http://www.egenix.com/
  mxODBC.Zope.Database.Adapter ...http://zope.egenix.com/
  mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

 

  Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! 

eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611

Marc-Andre,

Thanks for the reply.  I understand that this is normal locking
behavior.  What I am looking for is a standard method to either loop
the query until the table is unlocked, or put the query into some sort
of queue.  Basically my queries work like this.

Request comes in

PART I:
LOCK TABLE port_usage READ;
SELECT * FROM port_usage WHERE in_use = 0;
Get available port
UPDATE port_usage SET in_use = 1 WHERE port = available_port;
UNLOCK TABLES;

send request to available port and do some stuff until finished with
port

PART II:
LOCK TABLE port_usage READ
UPDATE port_usage SET in_use = 0 WHERE port = available_port;
UNLOCK TABLES;

Several of these *may* be happening simultaneously so when a second
request comes in, and the first one has the table locked, I want to
have the PART I sql still work.  Any suggestions here?

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


Re: Spawn new process - get pid

2008-02-05 Thread breal
On Feb 4, 9:25 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 On 4 feb, 22:21, breal [EMAIL PROTECTED] wrote:



  On Feb 4, 3:34 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:

   En Mon, 04 Feb 2008 20:59:16 -0200, breal [EMAIL PROTECTED]
   escribió:

I have a soap server written in Python that acts as an intermediary
between a web service and an InDesign server.  The indesign server is
non-threaded, so when all instances are used up I want to create a new
instance, get the pid, use the process, then kill it.

   Use the subprocess 
   module:http://docs.python.org/lib/module-subprocess.html

  Thanks for the reply.  Using subprocess.Popen I am able to get and
  kill the process.  However, the process I am running creates another
  process (an instance of InDesign Server) so when I kill the first
  process it doesn't kill the second.  Is there any way to capture both
  PIDs and kill them?

 I assume you're on *nix. Can you modify the first process? Make it a
 project group leader, then kill the whole group. I don't remember the
 details, try `man setpgrp` (or setpg?)

 --
 Gabriel Genellina

Ok, so at first I was calling a shell script that called another
program to start.  I have eliminated the middle-man shell script and
am now calling the program directly.  But here is my problem...

I need the program to start fully before I go on any further so that
it is available later in my script.  After it is used I need to kill
the pid of the program I started.  So, I was trying to use
my_process = subprocess.Popen([/path/to/my/program', -port, %s
%port_number, -configure, conf.%s %port_number], stdout=f1)
my_process.wait()
child_pid = my_process.pid

Is this the right way to do it?  It seems to be returning a different
pid for the process... so when I try to kill it I get a no such
process error.

Basically I have five instances of InDesign server running on various
ports.. 18400 - 18404.  When they are all in use, I want to start a
new instance... have it fully running... then use it and kill it.

Any help is appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spawn new process - get pid

2008-02-04 Thread breal
On Feb 4, 3:34 pm, Gabriel Genellina [EMAIL PROTECTED] wrote:
 En Mon, 04 Feb 2008 20:59:16 -0200, breal [EMAIL PROTECTED]
 escribió:

  I have a soap server written in Python that acts as an intermediary
  between a web service and an InDesign server.  The indesign server is
  non-threaded, so when all instances are used up I want to create a new
  instance, get the pid, use the process, then kill it.

  What is the best way to do this?  I don't want to replace the current
  process with the new one which is looks like os.exec* does.

 Use the subprocess module:http://docs.python.org/lib/module-subprocess.html

 --
 Gabriel Genellina

Thanks for the reply.  Using subprocess.Popen I am able to get and
kill the process.  However, the process I am running creates another
process (an instance of InDesign Server) so when I kill the first
process it doesn't kill the second.  Is there any way to capture both
PIDs and kill them?

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


Spawn new process - get pid

2008-02-04 Thread breal
I have a soap server written in Python that acts as an intermediary
between a web service and an InDesign server.  The indesign server is
non-threaded, so when all instances are used up I want to create a new
instance, get the pid, use the process, then kill it.

What is the best way to do this?  I don't want to replace the current
process with the new one which is looks like os.exec* does.

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


Creating unique combinations from lists

2008-01-16 Thread breal
I have three lists... for instance

a = ['big', 'small', 'medium'];
b = ['old', 'new'];
c = ['blue', 'green'];

I want to take those and end up with all of the combinations they
create like the following lists
['big', 'old', 'blue']
['small', 'old', 'blue']
['medium', 'old', 'blue']
['big', 'old', 'green']
['small', 'old', 'green']
['medium', 'small', 'green']
['big', 'new', 'blue']
['small', 'new', 'blue']
['medium', 'new', 'blue']
['big', 'new', 'green']
['small', 'new', 'green']
['medium', 'new', 'green' ]

I could do nested for ... in loops, but was looking for a Pythonic way
to do this.  Ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating unique combinations from lists

2008-01-16 Thread breal
On Jan 16, 11:33 am, Reedick, Andrew [EMAIL PROTECTED] wrote:
  -Original Message-
  From: [EMAIL PROTECTED] [mailto:python-
  [EMAIL PROTECTED] On Behalf Of breal
  Sent: Wednesday, January 16, 2008 2:15 PM
  To: [EMAIL PROTECTED]
  Subject: Creating unique combinations from lists

  I have three lists... for instance

  a = ['big', 'small', 'medium'];
  b = ['old', 'new'];
  c = ['blue', 'green'];

  I want to take those and end up with all of the combinations they
  create like the following lists
  ['big', 'old', 'blue']
  ['small', 'old', 'blue']
  ['medium', 'old', 'blue']
  ['big', 'old', 'green']
  ['small', 'old', 'green']
  ['medium', 'small', 'green']
  ['big', 'new', 'blue']
  ['small', 'new', 'blue']
  ['medium', 'new', 'blue']
  ['big', 'new', 'green']
  ['small', 'new', 'green']
  ['medium', 'new', 'green' ]

  I could do nested for ... in loops, but was looking for a Pythonic way
  to do this.  Ideas?

 http://www.python.org/dev/peps/pep-0202/

Thanks for the reply.  I never realized you could use list
comprehension like this... AWESOME!
-- 
http://mail.python.org/mailman/listinfo/python-list


Funny python cartoon... hope it's not a repost

2007-12-18 Thread Breal
http://xkcd.com/353/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Funny python cartoon... hope it's not a repost

2007-12-18 Thread Breal
On Dec 18, 11:56 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
 Breal a écrit :

 http://xkcd.com/353/

 Bad luck: it *is* a repost.

 While we're at it, did you notice the alternate text for the image ?-)

Did not notice the alt text... friggin hilarious!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Finding overlapping times...

2007-12-13 Thread Breal
I have a list that looks like the following
[(10, 100010), (15, 17), (19, 100015)]

I would like to be able to determine which of these overlap each
other.  So, in this case, tuple 1 overlaps with tuples 2 and 3.  Tuple
2 overlaps with 1.  Tuple 3 overlaps with tuple 1.

In my scenario I would have hundreds, if not thousands of these
ranges.  Any nice pythonic way to do this?

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