3
我用xmlrpc服務器運行簡單的例子,然後按下鍵盤上的Ctrl-C :)。按下鍵盤後xmlrpc服務器的問題
from SimpleXMLRPCServer import SimpleXMLRPCServer from time import sleep import threading,time class Test(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.test1 = 0 def test(self): return self.test1 def run(self): while(1): time.sleep(1) self.test1 = self.test1 + 1 ts = Test() ts.start() server = SimpleXMLRPCServer(("localhost",8888)) server.register_instance(ts) server.serve_forever()
錯誤:
File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever r, w, e = select.select([self], [], [], poll_interval) KeyboardInterrupt
客戶
from xmlrpclib import ServerProxy r=ServerProxy("http://localhost:8888") print r.test()等待連接沒有錯誤或警告。在這種情況下如何斷開連接? 也許這個例子不正確?
這不起作用希望python 2.7
– Bdfy 2011-04-14 16:18:03@Bdfy - 看到我編輯的答案與工作代碼 – 2011-04-14 16:58:36