Concurrency with class arguments

40 views
Skip to first unread message

太郎田中

unread,
Jan 24, 2016, 5:38:01 PM1/24/16
to rpyc
Hi there.
I have a minor issue where I can't run multiple services concurrently with class arguments.


"""server snippet"""
import rpyc
from rpyc.utils.server import ThreadedServer
import time


class Service(rpyc.Service):
    def exposed_test(self, credential):
        for i in xrange(10):
            print self, i
            time.sleep(1)


if __name__ == '__main__':
    server = ThreadedServer(
            Service, port=10000,
            protocol_config={'allow_all_attrs': True}
    )
    server.start()




"""client snippet(pass in class)"""
import rpyc

def make_connection():
    return rpyc.connect(
        'localhost', 10000, 
        config={'allow_all_attrs': True, 'allow_setattr': True})


class Argument(object):
    def __init__(self, value):
        self.value = value


arg_0 = Argument(0)
arg_1 = Argument(1)

print 'connecting'
connection_0 = make_connection()
connection_1 = make_connection()

print 'instantiating results'
async_0 = rpyc.async(connection_0.root.test)
async_1 = rpyc.async(connection_1.root.test)
result_0 = async_0(arg_0)
result_1 = async_1(arg_1)

print 'waiting'
result_0.wait()
result_1.wait()
result_0.value
result_1.value

"""server output(pass in class)"""
<__main__.Service object at 0x27be320> 0
<__main__.Service object at 0x27be320> 1
<__main__.Service object at 0x27be320> 2
<__main__.Service object at 0x27be320> 3
<__main__.Service object at 0x27be320> 4
<__main__.Service object at 0x27be320> 5
<__main__.Service object at 0x27be320> 6
<__main__.Service object at 0x27be320> 7
<__main__.Service object at 0x27be320> 8
<__main__.Service object at 0x27be320> 9
<__main__.Service object at 0x27b94d0> 0
<__main__.Service object at 0x27b94d0> 1
<__main__.Service object at 0x27b94d0> 2
<__main__.Service object at 0x27b94d0> 3
<__main__.Service object at 0x27b94d0> 4
<__main__.Service object at 0x27b94d0> 5
<__main__.Service object at 0x27b94d0> 6
<__main__.Service object at 0x27b94d0> 7
<__main__.Service object at 0x27b94d0> 8
<__main__.Service object at 0x27b94d0> 9




"""client snippet(pass in int)"""
import rpyc

def make_connection():
    return rpyc.connect(
        'localhost', 10000, 
        config={'allow_all_attrs': True, 'allow_setattr': True})


class Argument(object):
    def __init__(self, value):
        self.value = value

print 'connecting'
connection_0 = make_connection()
connection_1 = make_connection()

print 'instantiating results'
async_0 = rpyc.async(connection_0.root.test)
async_1 = rpyc.async(connection_1.root.test)
result_0 = async_0(0)
result_1 = async_1(1)

print 'waiting'
result_0.wait()
result_1.wait()
result_0.value
result_1.value

"""server output(pass in int)"""
<__main__.Service object at 0x27cdf38> 0
<__main__.Service object at 0x27ce4d0> 0
<__main__.Service object at 0x27ce4d0> 1
<__main__.Service object at 0x27cdf38> 1
<__main__.Service object at 0x27ce4d0> 2
<__main__.Service object at 0x27cdf38> 2
<__main__.Service object at 0x27ce4d0> 3
<__main__.Service object at 0x27cdf38> 3
<__main__.Service object at 0x27ce4d0> 4
<__main__.Service object at 0x27cdf38> 4
<__main__.Service object at 0x27ce4d0> 5
<__main__.Service object at 0x27cdf38> 5
<__main__.Service object at 0x27ce4d0> 6
<__main__.Service object at 0x27cdf38> 6
<__main__.Service object at 0x27ce4d0> 7
<__main__.Service object at 0x27cdf38> 7
<__main__.Service object at 0x27ce4d0> 8
<__main__.Service object at 0x27cdf38> 8
<__main__.Service object at 0x27ce4d0> 9
<__main__.Service object at 0x27cdf38> 9


As you can see, the former snippet is only running one method at a time.
Is there anything I could do to work around this? 
Any help would be appreciated.
Thanks.

Reply all
Reply to author
Forward
0 new messages