Skip to content

Commit

Permalink
Merge pull request #174 from PeterRK/master
Browse files Browse the repository at this point in the history
add callback in BgServingThread
  • Loading branch information
tomerfiliba committed Feb 10, 2016
2 parents c118a26 + 0a95f7c commit 73086ea
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rpyc/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ class BgServingThread(object):
SERVE_INTERVAL = 0.0
SLEEP_INTERVAL = 0.1

def __init__(self, conn):
def __init__(self, conn, callback=None):
self._conn = conn
self._thread = threading.Thread(target = self._bg_server)
self._thread.setDaemon(True)
self._active = True
self._callback = callback
self._thread.start()
def __del__(self):
if self._active:
Expand All @@ -205,7 +206,10 @@ def _bg_server(self):
time.sleep(self.SLEEP_INTERVAL) # to reduce contention
except Exception:
if self._active:
raise
self._active = False
if self._callback is None:
raise
self._callback()
def stop(self):
"""stop the server thread. once stopped, it cannot be resumed. you will
have to create a new BgServingThread object later."""
Expand Down

0 comments on commit 73086ea

Please sign in to comment.