Re: Python XMLRPC question

2009-10-15 Thread prasanna
Thanks a bunch. Qill give it a shot.

--p

On Oct 14, 8:18 pm, "Gabriel Genellina" 
wrote:
> En Wed, 14 Oct 2009 22:08:09 -0300,prasanna  
> escribió:
>
> > Out of curiosity--one more thing I haven't yet figured out, is there a
> > xmlrpc command I can send that stops or restarts the server?
>
> If you're using Python 2.6, the easiest way is to register its shutdown()  
> method. Note that it *must* be called from a separate thread (just inherit  
>  from ForkingMixIn)
>
> On earlier versions, overwrite the serve_forever loop (so it reads `while  
> not self._quit: ...`) and add a shutdown() method that sets self._quit to  
> True. You'll need to call shutdown twice in that case.
>
> === begin xmlrpcshutdown.py ===
> import sys
>
> def server():
>      from SocketServer import ThreadingMixIn
>      from SimpleXMLRPCServer import SimpleXMLRPCServer
>
>      # ThreadingMixIn must be included when publishing
>      # the shutdown method
>      class MyXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
>          pass
>
>      print 'Running XML-RPC server on port 8000'
>      server = MyXMLRPCServer(("localhost", 8000),
>          logRequests=False, allow_none=True)
>          # allow_none=True because of shutdown
>      server.register_function(lambda x,y: x+y, 'add')
>      server.register_function(server.shutdown)
>      server.serve_forever()
>
> def client():
>      from xmlrpclib import ServerProxy
>
>      print 'Connecting to XML-RPC server on port 8000'
>      server = ServerProxy("http://localhost:8000";)
>      print "2+3=", server.add(2, 3)
>      print "asking server to shut down"
>      server.shutdown()
>
> if sys.argv[1]=="server": server()
> elif sys.argv[1]=="client": client()
> === end xmlrpcshutdown.py ===
>
> C:\TEMP>start python xmlrpcshutdown.py server
>
> C:\TEMP>python xmlrpcshutdown.py client
> Connecting to XML-RPC server on port 8000
> 2+3= 5
> asking server to shut down
>
> C:\TEMP>
>
> --
> Gabriel Genellina

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


Re: Python XMLRPC question

2009-10-14 Thread Gabriel Genellina
En Wed, 14 Oct 2009 22:08:09 -0300, prasanna   
escribió:



Out of curiosity--one more thing I haven't yet figured out, is there a
xmlrpc command I can send that stops or restarts the server?


If you're using Python 2.6, the easiest way is to register its shutdown()  
method. Note that it *must* be called from a separate thread (just inherit  
from ForkingMixIn)


On earlier versions, overwrite the serve_forever loop (so it reads `while  
not self._quit: ...`) and add a shutdown() method that sets self._quit to  
True. You'll need to call shutdown twice in that case.


=== begin xmlrpcshutdown.py ===
import sys

def server():
from SocketServer import ThreadingMixIn
from SimpleXMLRPCServer import SimpleXMLRPCServer

# ThreadingMixIn must be included when publishing
# the shutdown method
class MyXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass

print 'Running XML-RPC server on port 8000'
server = MyXMLRPCServer(("localhost", 8000),
logRequests=False, allow_none=True)
# allow_none=True because of shutdown
server.register_function(lambda x,y: x+y, 'add')
server.register_function(server.shutdown)
server.serve_forever()

def client():
from xmlrpclib import ServerProxy

print 'Connecting to XML-RPC server on port 8000'
server = ServerProxy("http://localhost:8000";)
print "2+3=", server.add(2, 3)
print "asking server to shut down"
server.shutdown()

if sys.argv[1]=="server": server()
elif sys.argv[1]=="client": client()
=== end xmlrpcshutdown.py ===


C:\TEMP>start python xmlrpcshutdown.py server

C:\TEMP>python xmlrpcshutdown.py client
Connecting to XML-RPC server on port 8000
2+3= 5
asking server to shut down

C:\TEMP>

--
Gabriel Genellina

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


Re: Python XMLRPC question

2009-10-14 Thread prasanna
On Oct 13, 1:22 pm, "Gabriel Genellina" 
wrote:
> En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas  escribió:
>
>
>
>
>
> > On Oct 13, 12:47 pm,prasanna wrote:
> >> In using Python's XMLRPC, there is a statement that gets printed on
> >> stdout of the form:
> >>                  localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
> >> 1.0" 200 -
>
> >> Where does this message originate? Can I turn it off, or at least
> >> redirect it into a logging file? I am planning to run the server code
> >> automatically at start up and wouldn't have a terminal window open to
> >> get this message. I guess I could redirect/pipe it to a file, but it
> >> would be more useful I could send it to the same log file that I have
> >> the server writing other messages to.
>
> >> Thanks for any help.
>
> > Looking back through the SimpleXMLRPCServer code, it appears that this
> > happens if the logRequests parameter in the SimpleXMLRPCServer class
> > initialization is set to True, which it is by default. The underlying
> > implementation of the logging is in BaseHTTPServer.py, which uses
> > sys.stderr.
>
> > Looks like the simplest way to change that would be to inherit from
> > the SimpleXMLRPCRequestHandler class and implement your own
> > log_request method. You could then pass that to the SimpleXMLRPCServer
> > constructor.
>
> I think it's easier to pass logRequests=False when creating the server.
>
> --
> Gabriel Genellina

Thanks. That helped get rid of the message.

Out of curiosity--one more thing I haven't yet figured out, is there a
xmlrpc command I can send that stops or restarts the server?

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


Re: Python XMLRPC question

2009-10-13 Thread Falcolas
On Oct 13, 2:22 pm, "Gabriel Genellina" 
wrote:
> En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas  escribió:
[snip]
> > Looks like the simplest way to change that would be to inherit from
> > the SimpleXMLRPCRequestHandler class and implement your own
> > log_request method. You could then pass that to the SimpleXMLRPCServer
> > constructor.
>
> I think it's easier to pass logRequests=False when creating the server.
>
> --
> Gabriel Genellina

Indeed - I should probably be more explicit that my thoughts were
aimed at logging into their own file.

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


Re: Python XMLRPC question

2009-10-13 Thread Gabriel Genellina

En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas  escribió:


On Oct 13, 12:47 pm, prasanna  wrote:

In using Python's XMLRPC, there is a statement that gets printed on
stdout of the form:
                 localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
1.0" 200 -

Where does this message originate? Can I turn it off, or at least
redirect it into a logging file? I am planning to run the server code
automatically at start up and wouldn't have a terminal window open to
get this message. I guess I could redirect/pipe it to a file, but it
would be more useful I could send it to the same log file that I have
the server writing other messages to.

Thanks for any help.


Looking back through the SimpleXMLRPCServer code, it appears that this
happens if the logRequests parameter in the SimpleXMLRPCServer class
initialization is set to True, which it is by default. The underlying
implementation of the logging is in BaseHTTPServer.py, which uses
sys.stderr.

Looks like the simplest way to change that would be to inherit from
the SimpleXMLRPCRequestHandler class and implement your own
log_request method. You could then pass that to the SimpleXMLRPCServer
constructor.


I think it's easier to pass logRequests=False when creating the server.

--
Gabriel Genellina

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


Re: Python XMLRPC question

2009-10-13 Thread Falcolas
On Oct 13, 12:47 pm, prasanna  wrote:
> In using Python's XMLRPC, there is a statement that gets printed on
> stdout of the form:
>                  localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
> 1.0" 200 -
>
> Where does this message originate? Can I turn it off, or at least
> redirect it into a logging file? I am planning to run the server code
> automatically at start up and wouldn't have a terminal window open to
> get this message. I guess I could redirect/pipe it to a file, but it
> would be more useful I could send it to the same log file that I have
> the server writing other messages to.
>
> Thanks for any help.

Looking back through the SimpleXMLRPCServer code, it appears that this
happens if the logRequests parameter in the SimpleXMLRPCServer class
initialization is set to True, which it is by default. The underlying
implementation of the logging is in BaseHTTPServer.py, which uses
sys.stderr.

Looks like the simplest way to change that would be to inherit from
the SimpleXMLRPCRequestHandler class and implement your own
log_request method. You could then pass that to the SimpleXMLRPCServer
constructor.

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


Python XMLRPC question

2009-10-13 Thread prasanna
In using Python's XMLRPC, there is a statement that gets printed on
stdout of the form:
 localhost - - [12/Oct/2009 23:36:12] "POST /RPC2 HTTP/
1.0" 200 -

Where does this message originate? Can I turn it off, or at least
redirect it into a logging file? I am planning to run the server code
automatically at start up and wouldn't have a terminal window open to
get this message. I guess I could redirect/pipe it to a file, but it
would be more useful I could send it to the same log file that I have
the server writing other messages to.

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