@defer.deferredGenerator
   def _scan(self):
       for pid in listProcesses():
           try: AppProcess(Server(config.HOSTNAME), pid)
           except InvalidProcess: pass
           except IOError: pass #happens on linux when a pid dies
           except: err('process table scanning error')
       #scan for crashed instances
       for app in App.objects:
           if not app.__class__.isValid(app): continue
           for ai in app.localappinstances:
               if not ai.__class__.isValid(ai): continue
               if ai in self.tracking: continue
               if not self.first_run: #avoid process table races
                   self.tracking.add(ai)
                   config.reactor.callLater(SERVICECONFIG.recovery_period,
                       self.tracking.discard, ai
                   )
                   if not ai.enabled: continue #skip disabled
               result = None
               if ai.running and not ai.shouldBeRunning:
                   ai.shouldBeRunning = True
               if ai.running: continue
               manager = AppManager(ai.app.name)
               if not manager.running:
                   continue #skip managers that are not running
               if not manager.discover:
                   continue #app manager claims to be ok
               #look for processes that we can assimilate
               d = manager.model.findProcesses()
               wfd = defer.waitForDeferred(d)
               yield wfd
               for (pid, result) in wfd.getResult():
                   d = manager.model.assimilateProcess(result)
                   wfd2 = defer.waitForDeferred(d)
                   yield wfd2
                   ai2 = wfd2.getResult()
                   if ai2 and isinstance(ai2, AppInstance) and ai2 is ai:
                       Event('instance-found').fire(instance=ai)
                       manager.log('Sucessfully assimilated PID %d' % ai2.pid)
               if ai.running: continue #may have assimilated the app
               if not ai.crashed: continue
               if not ai.enabled: continue #disabled instances are not actionable
               if self.first_run: continue #avoid process table races
               Event('instance-crashed').fire(instance=ai)
               #cool off on eventing for a little while
       #keep the process objects up to date
       for process in AppProcess.objects:
           try:
               if not process.localInstall: continue
               if not process.running:
                   AppProcess.delete(process)
           except:
               err('process book keeping error')
       d = defer.Deferred()
       config.reactor.callLater(0.01, d.callback, None)
       wfd = defer.waitForDeferred(d)
       yield wfd
       wfd.getResult()
       self.first_run = False
       yield 'done'
dataset/ETHPy150Open OrbitzWorldwide/droned/droned/services/application.py/ApplicationLoader._scan/original