Regarding BgServingThread

138 views
Skip to first unread message

Cihat

unread,
Oct 12, 2009, 12:45:39 AM10/12/09
to rpyc
Hi,

The line 4 takes a bit of time, in the order of 10 seconds sometimes.
However, when I put line 4 above line 2. There is no problem. Is it
because that after creating the bg thread, the main thread and bg
thread share the same connection object, hence at line 4, the main
thread may be starved if the bgsrv holds on to the conn object for a
long time (i.e. possibly contending for the same lock and happens to
be that the bgsrv acquires the lock over and over again thus is
starves the main thread)?

1: conn = rpyc.connect(...)
2: bgsrv = rpyc.BgServingThread(conn)
3: print "I am after bgsrv"
4: fun = rpyc.async(conn.root.test)

Thanks,
Cihat.

tomer filiba

unread,
Oct 13, 2009, 9:01:00 AM10/13/09
to rp...@googlegroups.com
python's thread model is basically a big pile of voodoo. it doesn't work consistently, as cpython itself is not thread safe.
what blocks in your code is the getattr -- conn.root or conn.root.test. this is because the bg serving thread holds the connection mutex almost exclusively. i have no real solution for that -- the lock is released by the bg thread, while the main thread waits for it, but instead of the main thread acquiring it, the bg thread acquires it again.

you can try adding sleep(0.1) in the code of BgServerThread:
    def _bg_server(self):
        try:
            while self._active:
                self._conn.serve(self.INTERVAL)
time.sleep(0.1)
        except Exception:
            if self._active:
                raise
my tests show it helps... sorry i can't do more :-/

-tomer

An NCO and a Gentleman

firstway

unread,
Oct 13, 2009, 10:48:47 AM10/13/09
to rpyc
there is an article about this issue
http://linuxgazette.net/107/pai.html

tomer filiba

unread,
Oct 13, 2009, 12:37:23 PM10/13/09
to rp...@googlegroups.com
that's a nice reading, thanks!



An NCO and a Gentleman


Reply all
Reply to author
Forward
0 new messages