Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions python/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,34 @@ def balance(self):

def send(self, data):
sup = super(QueueChannel, self)
with threading.Lock():
if sup.balance >= 0 and not sup.closing:
self.data_queue.append((True, data))
else:
sup.send(data)
if sup.balance >= 0 and not sup.closing:
self.data_queue.append((True, data))
else:
sup.send(data)

def send_exception(self, exc, *args):
self.send_throw(exc, args)

def send_throw(self, exc, value=None, tb=None):
"""call with similar arguments as raise keyword"""
sup = super(QueueChannel, self)
with threading.Lock():
if sup.balance >= 0 and not sup.closing:
self.data_queue.append((False, (exc, value, tb)))
else:
#deal with channel.send_exception signature
sup.send_throw(exc, value, tb)
if sup.balance >= 0 and not sup.closing:
self.data_queue.append((False, (exc, value, tb)))
else:
#deal with channel.send_exception signature
sup.send_throw(exc, value, tb)

def receive(self):
with threading.Lock():
if not self.data_queue:
return super(QueueChannel, self).receive()
ok, data = self.data_queue.popleft()
if ok:
return data
exc, value, tb = data
try:
raise exc(value).with_traceback(tb)
finally:
tb = None
if not self.data_queue:
return super(QueueChannel, self).receive()
ok, data = self.data_queue.popleft()
if ok:
return data
exc, value, tb = data
try:
raise exc(value).with_traceback(tb)
finally:
tb = None

#iterator protocol
def send_sequence(self, sequence):
Expand Down