intervall of about 1 second for xmlrpc calls?

T

Thomas Lehmann

Hi,

I'm wondering about the behavior. Running this example - it looks like
- that each rpc call is triggered in a visible interval (about one
second).

What's wrong?

Thomas

APPENDIX:

<code>
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client

class MyServer(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.server = SimpleXMLRPCServer((host, port))
self.server.register_function(self.is_even, "is_even")
self.server.register_function(self.stop, "stop_server")

def run(self):
print("server: waiting for requests...")
self.server.serve_forever()
print("server: is down.")

def stop(self):
print("server: shutdown requested...")
self.stoptimer = threading.Timer(1, self.server.shutdown)
self.stoptimer.start()
return "done."

def is_even(self, n):
print("server: check %d to be even" % (n))
return n%2 == 0


# server as thread
server = MyServer("localhost", 1234)
server.start()

# client code
serverProxy = xmlrpc.client.ServerProxy("http://localhost:1234")
for n in range(1,2+1):
print("%d is %s" % (n, ["odd", "even"][serverProxy.is_even(n)]))
serverProxy.stop_server()
</code>
 
T

Thomas Lehmann

What's wrong?
Obviously there's a problem with "localhost". When using the IP of my
machine everything is working fast.
 
A

Adam Tauno Williams

Obviously there's a problem with "localhost". When using the IP of my
machine everything is working fast.

You box may first be trying to connect to ::1 (ipv6) and when that fails
it falls back to 127.0.0.1. Make sure IPv6 is properly
configured/enabled and try the script again.
 
N

News123

Hi Adam,


I think you're right.

localhost with IPV6 was also a problem for me. At least it was for me
on a windows 7 host.
I 'solved' the problem by disabling IPV6, but this is a workaround, not
a proper solution.
You box may first be trying to connect to ::1 (ipv6) and when that fails
it falls back to 127.0.0.1. Make sure IPv6 is properly
configured/enabled and try the script again.

Do you know why the default config of IPV6 could be wrong on a windows
7 host?

Having no experience with IPV6:

How should it be configured?
How to detect issues?


thanks


N
 
A

Adam Tauno Williams

Hi Adam,

I think you're right.
localhost with IPV6 was also a problem for me. At least it was for me
on a windows 7 host.
I 'solved' the problem by disabling IPV6, but this is a workaround, not
a proper solution.
Do you know why the default config of IPV6 could be wrong on a windows
7 host?

No. This would seem to have something to do with the resolver. If you
do a nslookup for localhost what does it say.
Having no experience with IPV6:

Have lots, it's really nice. Once you get most things cut over.
How should it be configured?
How to detect issues?

Does nslookup localhost return the correct result? That might depend on
your DNS server - not your local host.

Also "ping ::1"?
 
R

rav

I had similar problem with SimpleXMLRPCServer
Create the request handler class

class ExtendedXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# originally this one was slowing down my server A LOT due to DNS
settings!!!
def log_request(self, *args):
pass

and put it in your SimpleXMLRPCServer constructor

(...)

class MyServer(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.server = SimpleXMLRPCServer((host, port),
ExtendedXMLRPCRequestHandler)
self.server.register_function(self.is_even, "is_even")
self.server.register_function(self.stop, "stop_server")

(...)

I would also change all 'localhost' occurences in the code to ip
'127.0.0.1'.

Good luck!
Rafal
 
A

Adam Tauno Williams

I had similar problem with SimpleXMLRPCServer
Create the request handler class
class ExtendedXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# originally this one was slowing down my server A LOT due to DNS
settings!!!
def log_request(self, *args):
pass
and put it in your SimpleXMLRPCServer constructor
(...)
class MyServer(threading.Thread):
def __init__(self, host, port):
threading.Thread.__init__(self)
self.server = SimpleXMLRPCServer((host, port),
ExtendedXMLRPCRequestHandler)
self.server.register_function(self.is_even, "is_even")
self.server.register_function(self.stop, "stop_server")
(...)
I would also change all 'localhost' occurences in the code to ip
'127.0.0.1'.

Or the better solution is to fix your resolver.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top