code: def _remove_deactivated(contexts):
      """Remove deactivated handlers from the chain"""
      # Clean ctx handlers
      stack_contexts = tuple([h for h in contexts[0] if h.active])
  
      # Find new head
      head = contexts[1]
      while head is not None and not head.active:
          head = head.old_contexts[1]
  
      # Process chain
      ctx = head
      while ctx is not None:
          parent = ctx.old_contexts[1]
  
          while parent is not None:
              if parent.active:
                  break
              ctx.old_contexts = parent.old_contexts
              parent = parent.old_contexts[1]
  
          ctx = parent
  
      return (stack_contexts, head)
  
imports: from __future__ import absolute_import, division, print_function, with_statement
  import sys
  import threading
  from .util import raise_exc_info
label_desc: Use image node_id 1 for calling a global function with example usage: _remove_deactivated(contexts) and returns: stack_contexts,  head