Temporarily disable zope.lifecycle events?

I got an folderish contenttype with large audio files on it. A subscriber on that object calculates audio peaks on creation or modification.

Now I should change (delete/recreate) contents within that folderish object, resulting in cpu intensive recalculation of those peaks on delete and on recreate of objects within.

Is there a way to temporarily disable a certain event subscriber within the upgrade step that does the altering of the contents? Other ideas?

I'd add a flag to the module where the handler is, and monkey patch that in the upgrade.
Make sure to reset it to the old value though.
You could use a try..finally construct or a context manager to do this in the upgrade step.
This does mean that while running the upgrade step uploads for other users will not be handled correctly.

Another option would be to set an DONT_PROCESS_ME_PLEASE flag on the object. Then remove it when you can handle the CPU spikes.

1 Like

DONT_PROCESS_ME_PLEASE looks like a sane way in this case.

I put an example of disabling and re-enabling a subscriber in bobtemplates.migration: https://github.com/collective/bobtemplates.migration/blob/master/bobtemplates/migration/jsonify/src/%2Bpackage.namespace%2B/%2Bpackage.name%2B/upgrades.py.bob

it uses getGlobalSiteManager().unregisterHandler() and registerHandler()