furious icon indicating copy to clipboard operation
furious copied to clipboard

AutoContext - Calling set_event_handler() after adding tasks may not work as desired

Open markshaule-wf opened this issue 11 years ago • 0 comments

This is more of an annoyance, but when using an AutoContext to add tasks in batch, you may get undesired results if you don't set the event handler up front.

So the following may not work - as only your last batch would get a completion checker attached:

with context.new(batch_size=10) as ctx:
    for item in items:
        ctx.add(target=my_func)
    ctx.set_event_handler('complete',  completion_handler)

as a work around, always set the event handler first,

with context.new(batch_size=10) as ctx:
    ctx.set_event_handler('complete',  completion_handler)
    for item in items:
        ctx.add(target=my_func)

markshaule-wf avatar Sep 25 '14 21:09 markshaule-wf