question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove handler feature in Engine

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonkrisscommented, Mar 7, 2019

Got it! Thanks for the added context. Helps a lot. Let’s go ahead and add it then.

0reactions
vfdev-5commented, Mar 6, 2019

Would it maybe more clear here to use two stats_collectors rather than having to remember to remove the handler?

@jasonkriss it means that we need to copy previous code to reinit another stats_collectors

Is there a benefit to cleaning up after it finishes?

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 after profiler.attach(trainer) is called. So, once trainer.run(train_loader) is done, profiler computed what it needs and should remove its added handlers. Otherwise, on the second call of trainer.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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found