Python XMLRPC question

P

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.
 
F

Falcolas

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
 
G

Gabriel Genellina

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.
 
F

Falcolas

En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas <[email protected]> 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.

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

Garrick
 
P

prasanna

En Tue, 13 Oct 2009 16:55:09 -0300, Falcolas <[email protected]> escribió:




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.

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
 
G

Gabriel Genellina

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>
 
P

prasanna

Thanks a bunch. Qill give it a shot.

--p

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top