Reference 〉 Function

Hooks.remove(placestr, fnamestr|list[str], removeallboolFalse)

Removes one or more previously registered hooks by the function name.

Parameters

  • place str, required

    The hook from which to remove a function. If this is the only argument, all hooks to place will be removed.

  • fname str|list[str], required

    The name of the function registered to the hook, or a list of such names. Hooks registered with an argument-less @heli.hook decorator will have the same name as place.

  • removeall bool, optional

    By default, this function will stop after the first instance of a hook function matching name. Setting removeall=True will remove all functions with the given name. This might be the case if multiple functions are hooked using an argument-less @heli.hook, in which case the functions will all have the name of the hook.

    Default value: False

Return Value bool|list[bool]

Whether a matching named hook function in fact existed and was removed, or a list corresponding to the elements of the name parameter if a list was passed.

Notes and Examples

  1. charwick

    Nov 29, 2020 at 16:46

    A few examples of hooking and unhooking:

    from helipad import *
    heli = Helipad()
    
    @heli.hook
    def terminate(model, data):
    	print('Function 1')
    
    @heli.hook
    def terminate(model, data):
    	print('Function 2')
    
    @heli.hook('terminate')
    def arbitraryName(model, data):
    	print('Function 3')
    
    heli.hooks.remove('terminate', 'terminate') #Removes function 1
    heli.hooks.remove('terminate', 'terminate', True) #Removes functions 1 and 2
    heli.hooks.remove('terminate', 'arbitraryName') #Removes function 3
    heli.hooks.remove('terminate') #Removes all three functions

    It is recommended to use the @heli.hook('hookName') syntax with a unique function name, as in function 3 above, if you plan to remove the hook later.

  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History