Zhou Zheng Sheng has posted comments on this change.
Change subject: Adding threads limitation to misc.tmap
......................................................................
Patch Set 8: Looks good to me, but someone else must approve
Yaniv, your thoughts is very reasonable. The current implementation looks good
to me. I find it's hard to reuse itmap unless we make some modifications to it.
I can propose a way to reuse itmap. I am not good at written English, so if you
do not mind, I can explain the idea with code.
Firstly, we shoud let wrapper function in itmap produce an index with result.
def wrapper(ind, value):
try:
respQueue.put((ind, func(value)))
except Exception, e:
respQueue.put((ind, e))
Secondly, in itmap, we should provide the the index to the wrapper.
for ind, arg in enumerate(iterable):
t = threading.Thread(target=wrapper, args=(ind, arg,))
t.start()
At last, in tmap, we can get the index and value from itmap as follow,
def tmap(func, iterable, maxthreads=UNLIMITED_THREADS):
ex = None
resultDict = {}
for ind, r in itmap(func, iterable, maxthreads):
if isinstance(r, Exception):
ex = r
else
resultDict[ind] = result
if ex is not None:
raise ex
results = [None] * len(resultsDict)
for i, result in resultsDict.iteritems():
results[i] = result
return results
Untested, please treat as pseudocode.
--
To view, visit http://gerrit.ovirt.org/8858
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I07845bfd78b9215e8994ac2ebe46a7ff78c85625
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
Gerrit-Reviewer: Saggi Mizrahi <[email protected]>
Gerrit-Reviewer: ShaoHe Feng <[email protected]>
Gerrit-Reviewer: Shu Ming <[email protected]>
Gerrit-Reviewer: Yaniv Bronhaim <[email protected]>
Gerrit-Reviewer: Zhou Zheng Sheng <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches