mirror of
				https://github.com/YosysHQ/sby.git
				synced 2025-11-04 06:39:11 +00:00 
			
		
		
		
	simplify graph traversal code
This commit is contained in:
		
							parent
							
								
									daa8329baa
								
							
						
					
					
						commit
						7ac54c6a2e
					
				
					 1 changed files with 12 additions and 12 deletions
				
			
		| 
						 | 
					@ -28,24 +28,23 @@ class PROCESSENTRY32(Structure):
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _all_children(pid, lookup, visited):
 | 
					def _visit_all_children(pid, lookup, visited):
 | 
				
			||||||
    if pid in lookup and pid not in visited:
 | 
					    if pid not in visited:
 | 
				
			||||||
        visited.add(pid)
 | 
					        visited.add(pid)
 | 
				
			||||||
 | 
					        if pid in lookup:
 | 
				
			||||||
            for c in lookup[pid]:
 | 
					            for c in lookup[pid]:
 | 
				
			||||||
            if c not in visited:
 | 
					                _visit_all_children(c, lookup, visited)
 | 
				
			||||||
                visited.add(c)
 | 
					 | 
				
			||||||
                visited |= _all_children(c, lookup, visited)
 | 
					 | 
				
			||||||
        return visited
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        return set()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _update_lookup(pid_lookup, pe):
 | 
					def _update_lookup(pid_lookup, pe):
 | 
				
			||||||
    cpid = pe.contents.th32ProcessID
 | 
					    cpid = pe.contents.th32ProcessID
 | 
				
			||||||
    ppid = pe.contents.th32ParentProcessID
 | 
					    ppid = pe.contents.th32ParentProcessID
 | 
				
			||||||
    # pid 0 should be the only one that is its own parent
 | 
					    # pid 0 should be the only one that is its own parent.
 | 
				
			||||||
 | 
					    # don't add this entry to the graph to avoid an unwanted cycle
 | 
				
			||||||
 | 
					    if ppid == 0 and cpid == 0:
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
    assert (
 | 
					    assert (
 | 
				
			||||||
        cpid == 0 or cpid != ppid
 | 
					        cpid != ppid
 | 
				
			||||||
    ), "Internal error listing windows processes - process is its own parent"
 | 
					    ), "Internal error listing windows processes - process is its own parent"
 | 
				
			||||||
    if ppid not in pid_lookup:
 | 
					    if ppid not in pid_lookup:
 | 
				
			||||||
        pid_lookup[ppid] = []
 | 
					        pid_lookup[ppid] = []
 | 
				
			||||||
| 
						 | 
					@ -78,7 +77,8 @@ def win_killpg(pid):
 | 
				
			||||||
    first and use this to derive a list of child processes to be killed.
 | 
					    first and use this to derive a list of child processes to be killed.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    pid_lookup = _create_process_lookup()
 | 
					    pid_lookup = _create_process_lookup()
 | 
				
			||||||
    to_kill = _all_children(pid, pid_lookup, set())
 | 
					    to_kill = set()
 | 
				
			||||||
 | 
					    _visit_all_children(pid, pid_lookup, to_kill)
 | 
				
			||||||
    for p in to_kill:
 | 
					    for p in to_kill:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            # "Any other value for sig will cause the process to be
 | 
					            # "Any other value for sig will cause the process to be
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue