Enrico Polesel
Enrico Polesel

Reputation: 141

RPyC serve_all blocking threads access to connection

When in a multithreaded application i call rpyc.Connection.serve_all() from a thread other threads are unable to immediately use the connection.

I think that serve_all is blocking the connection and the other threads are able to access it only when there is some timeout.

This code should reproduce the issue

Server:

#!/usr/bin/env python3

import rpyc
import rpyc.utils.server
import threading

class Service(rpyc.Service):
    def on_connect(self):
        print("New connection")

    def on_disconnect(self):
        print("Connection closed")

    def exposed_get_status(self):
        return "Test string"

server = rpyc.utils.server.ThreadedServer(Service, port = 12345)
t = threading.Thread(target = server.start)
t.daemon = True
t.start()
t.join()

Client:

#!/usr/bin/env python3

import rpyc
import threading
import datetime

con = rpyc.connect('localhost',12345)

def delayed():
    print("Time is up")
    now = datetime.datetime.now()
    print(con.root.get_status())
    print(str(datetime.datetime.now() - now))

timer = threading.Timer(10,delayed)

print("Starting timer")
timer.start()
print("serving all")
con.serve_all()

Sample output (from the client):

$ python3 testrpyc.py 
Starting timer
serving all
Time is up
Test string
0:01:30.064087

I'm using RPyC 3.4.3 on Python 3.5.4rc1 (debian sid) installed with pip.

I think I'm misusing serve_all, but I can't find anything in the docs.

Upvotes: 1

Views: 1079

Answers (1)

Enrico Polesel
Enrico Polesel

Reputation: 141

(Answering myself)

I opened a issue on github and it seems that this is normal. The solution is to use perform IO only on a single thread for any resource.

Upvotes: 0

Related Questions