Fix ng-killall by swallowing psutil exceptions in filter

Review Request #4237 — Created Sept. 13, 2016 and submitted

nhoward_tw
pants
3840, 3869
pants-reviews
jsirois, kwlzn, zundel
ng-killall will fail to kill nailguns if there is a process earlier in the process list that has attributes that can't be accessed.

This patch wraps ProcessManager.process_iter's filter with a exception swallow call which allows it to continue if the filter calls a psutil error causing method.

Wrote unit tests exhibiting the behavior I was seeing and made them pass. Tried running ng-killall after the change and saw it work.

BE
  1. God bless you! This has been driving me nuts.

  2. 
      
KW
  1. lgtm - thanks!

  2. src/python/pants/pantsd/process_manager.py (Diff revision 1)
     
     
     
     
     
     

    not a big deal, but this naming stomps on the filter builtin - causes RB/IDEs/etc to highlight filter oddly.

    >>> filter
    <built-in function filter>
    
    1. Maybe even just collapse everything:

      with swallow_psutil_exceptions():  # process_iter may raise
        for proc in psutil.process_iter():
          with swallow_psutil_exceptions():  # proc_filter may raise
            if (proc_filter is None) or proc_filter(proc):
              yield proc
      
    2. That's much clearer.

  3. 
      
JS
  1. Ship It!
  2. 
      
NH
JS
  1. 
      
  2. ...subsequent processes will.
  3. 
      
NH
NH
Review request changed

Status: Closed (submitted)

Change Summary:

Submitted as https://github.com/pantsbuild/pants/commit/3e6e2125171ee6758d1b57e329b75c48c2cba2bb
Loading...