You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
as we can see future.py has no locks, when we use kafka proudcer's method send and add callback, the callback may never called;
when execute success, success callback are called by sender thread, and we add callback in our's work thread;
as 1-5 steps, callback will never be called
# work threadkafka_producer.send(topic, value).add_both(callback)
defsuccess(self, value):
# called by senderassertnotself.is_done, 'Future is already complete'## 1 if sender thread execute here and then stop and switch to work thread#self.value=valueself.is_done=Trueifself._callbacks:
self._call_backs('callback', self._callbacks, self.value)
# 4 sender thread execute finished and switch to work threadreturnselfdeffailure(self, e):
assertnotself.is_done, 'Future is already complete'self.exception=eiftype(e) isnottypeelsee()
assertisinstance(self.exception, BaseException), (
'future failed without an exception')
self.is_done=Trueself._call_backs('errback', self._errbacks, self.exception)
returnselfdefadd_callback(self, f, *args, **kwargs):
ifargsorkwargs:
f=functools.partial(f, *args, **kwargs)
## 2 work thread execute here and is_done is still False # ifself.is_doneandnotself.exception:
self._call_backs('callback', [f], self.value)
else:
# 3 work thread stop here and been switch to sender threadself._callbacks.append(f)
# 5 work thread add callback , but this call back will never be calledreturnself
The text was updated successfully, but these errors were encountered:
as we can see future.py has no locks, when we use kafka proudcer's method send and add callback, the callback may never called;
when execute success, success callback are called by sender thread, and we add callback in our's work thread;
as 1-5 steps, callback will never be called
The text was updated successfully, but these errors were encountered: