Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit Upadhyay committed Mar 5, 2011
1 parent bce9559 commit 3a82a73
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions dutils/zutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ def run(self):
self.socket.close()
break
self.socket.send(msg)
self.q.task_done()
# }}}

# ZSubscriber # {{{
class ZSubscriber(threading.Thread):
def __init__(self, bind, glob=""):
def __init__(self, bind, glob="", start=True):
super(ZSubscriber, self).__init__()
self.daemon = True
self.bind = bind
self.glob = glob
self.start()
if start: self.start()

def process(self, msg): print msg

def run(self):
self.socket = CONTEXT.socket(zmq.SUB)
self.socket.connect(self.bind)
if type(self.bind) == list:
for bind in self.bind:
self.socket.connect(bind)
else:
self.socket.connect(self.bind)
if type(self.glob) == list:
for glob in self.glob:
self.socket.setsockopt(zmq.SUBSCRIBE, glob)
Expand Down Expand Up @@ -172,7 +177,7 @@ def loop(self):
def process_command(msg):
args_part = msg.split("{", 1)[0]
json_part = msg[len(args_part):]
if json_part and args_part and args_part[-1] == ":":
if json_part and args_part and args_part[-1] == ":":
args_part = args_part[:-1]
args_part = args_part.split(":") if args_part else []
if json_part:
Expand Down

0 comments on commit 3a82a73

Please sign in to comment.