Remove handler feature in Engine
See original GitHub issueI recently encountered the cases where I would like to remove a handler and optionally replace it with another one. The following code is used:
def remove_handler(engine, handler, event_name):
assert event_name in engine._event_handlers
engine._event_handlers[event_name] = [(h, args, kwargs)
for h, args, kwargs in engine._event_handlers[event_name]
if h != handler]
@alykhantejani @jasonkriss what do you guys think about inserting such method into Engine
?
cc @anmolsjoshi
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
F# remove function handler - Stack Overflow
So, I have a function that I want to execute on an event trigger, but I want to remove it later. What do...
Read more >Can't remove SSLHandler after failed handshake · Issue #11454
When handshakeFuture is resolved and result is failed it's possible to remove SSLHandler from the pipeline. Actual behavior. io.netty.channel.
Read more >Action Handlers: Restrictions and Best Practices - IBM
You require that the handler is invoked only by the firing of specific events on the source object (rather than any create, update,...
Read more >Engine — PyTorch-Ignite v0.4.10 Documentation
Remove event handler handler from registered handlers of the engine. run. Runs the process_function over the passed data. set_data. Method to set data....
Read more >Events and Event Handlers Overview | Unreal Engine 4.27 ...
This page gives basic information about using Events and Event Handlers in Niagara.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got it! Thanks for the added context. Helps a lot. Let’s go ahead and add it then.
@jasonkriss it means that we need to copy previous code to reinit another
stats_collectors
…More on the context: I wrote a basic time profiler that collects times spent in handlers, batch preparation and process function. To do this the profiler adds manually its handlers in the special order: the first and the last handlers on the events. Profiler adds its handlers once the
run
is called to avoid the situation when user adds other handlers afterprofiler.attach(trainer)
is called. So, oncetrainer.run(train_loader)
is done, profiler computed what it needs and should remove its added handlers. Otherwise, on the second call oftrainer.run(train_loader)
there will be twice more attached handlers and times collection will be difficult or even faulty.EDIT: even for symmetry with the methods we already have: add, has, event handler. Remove is missing 😃