fredri...@gmail.com
unread,Aug 12, 2008, 6:35:44 PM8/12/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rpyc
Hello!
I have bin experimenting with rpyc and I must say I am very impressed.
However I can't get the callback to work properly. Basically what I'm
trying to do is to get the remote computer to call the callback
function once every second. This is my script:
---------------------------------------------------------
server.py:
import rpyc
import rpyc.utils.server
import time
import threading
class TestService(rpyc.Service):
def exposed_startTimer(self, callback):
callback = rpyc.async(callback)
self.timer = threading.Timer(1, self.doCallback, [callback,])
self.timer.start()
def exposed_stopTimer(self):
self.timer.cancel()
def doCallback(self, callback):
callback(time.time())
self.timer = threading.Timer(1, self.doCallback, [callback,])
self.timer.start()
server = rpyc.utils.server.ThreadedServer(TestService, port = 1234)
server.start()
---------------------------------------------------------
client.py
import rpyc
import time
def printTime(time):
print 'The remote time is ' + str(time)
connection = rpyc.connect('localhost', 1234)
connection.root.startTimer(printTime)
time.sleep(5)
connection.root.stopTimer()
---------------------------------------------------------
This works, except that all callbacks arrives first when I call
stopTimer(). I have also tried to start a new thread in the client
that calls connection.serve_all(). That works as long as the timer is
started, but then the call to stopTimer() never returns :/
I'm thankful for any help!
/Fredrik