-
Notifications
You must be signed in to change notification settings - Fork 87
Sub-handlers in a resume handlers are executed not in parallel #214
Comments
Hm. That is interesting. @e0ne Can you please describe ho do you check that the handlers are executed in parallel? The handlers for one single object are never executed in parallel, they are always sequential by design. More on that, it is not possible that the creation & update events happen at the same time (for update to happen, the object must be created already). Multiple different objects are handled in parallel though (each with its own sequence of handlers). This is also valid for the sub-handlers: they are executed in sequence (not necessary in the order given, but at most one at a time), and the original top-level handler is waiting for them. So, it is not clear what do you mean that create/update are executed in parallel. Also, I see that you call I assume, you have taken it from the docs at https://kopf.readthedocs.io/en/latest/handlers/, don't you? It seems, the example there is wrong. Another page is more correct on Notice, that for If actual parallel execution (but not handling) is needed, it is better to use the Python's parallelisation with threads or asyncio tasks. Just as a rough idea: import asyncio
import kopf
@kopf.on.update('zalando.org', 'v1', 'kopfexamples')
@kopf.on.create('zalando.org', 'v1', 'kopfexamples')
async def create_fn(spec, **kwargs):
tasks = {}
for item in spec.get('items', []):
tasks[item] = asyncio.create_task(handle_item(item=item, spec=spec, **kwargs))
done, pending = asyncio.wait(list(tasks.values()))
async def handle_item(item, *, spec, **_):
pass Same for threads and regular The specific implementations are outside of the Kopf's scope, so this parallelisation pattern is not a part of it. |
With
See #230 for details. I assume, the issue is fixed. The "parallel execution" issue is explained above — it never existed, and, perhaps, is just a terminology misunderstanding. If the issue with the on-resume handlers continues to reappear in |
Expected Behavior
Sub-handlers in a 'resume' event should be executed in parallel.
Actual Behavior
I've got one function both for create/update and resume events handling. create/update sub-handlers work in parallel without any issues. The same code for a resume event handler is executed one-by-one.
Steps to Reproduce the Problem
Specifications
The text was updated successfully, but these errors were encountered: