Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions nimp/base_commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,14 @@ def configure_arguments(self, env, parser):

def _run_check(self, env):
logging.info('Checking running processes…')
logging.info(f'Active filters: {", ".join(env.filters)}…')

# Irrelevant on sane Unix platforms
if not nimp.sys.platform.is_windows():
return True

# Irrelevant if we’re not an Unreal project
if not hasattr(env, 'is_unreal') or not env.is_unreal:
return True

# Find all running binaries launched from the project directory
# and optionally kill them, unless they’re in the exception list.
# Find all running binaries launched from the root dir
# and optionally kill them
# We get to try 5 times just in case
for _ in range(5):
found_problem = False
Expand All @@ -159,10 +156,13 @@ def _run_check(self, env):
if not any(fnmatch.fnmatch(info[0], filter) for filter in env.filters):
continue
process_basename = os.path.basename(info[0])
processes_ignore_patterns = _Processes.get_processes_ignore_patterns()
if any([re.match(p, process_basename, re.IGNORECASE) for p in processes_ignore_patterns]):
logging.info(f'process {pid} {info[0]} will be kept alive')
continue

if hasattr(env, 'is_unreal') and env.is_unreal:
processes_ignore_patterns = _Processes.get_unreal_processes_ignore_patterns()
if any([re.match(p, process_basename, re.IGNORECASE) for p in processes_ignore_patterns]):
logging.info(f'process {pid} {info[0]} will be kept alive')
continue

logging.warning('Found problematic process %s (%s)', pid, info[0])
found_problem = True
if info[1] in processes:
Expand All @@ -171,6 +171,8 @@ def _run_check(self, env):
logging.info('Killing process…')
nimp.sys.process.call(['wmic', 'process', 'where', 'processid=' + pid, 'delete'])
logging.info('%s processes checked.', len(processes))
logging.info(f'Active filters: {", ".join(env.filters)}…')

if not env.kill:
return not found_problem
if not found_problem:
Expand All @@ -180,7 +182,7 @@ def _run_check(self, env):
return False

@staticmethod
def get_processes_ignore_patterns():
def get_unreal_processes_ignore_patterns():
return [
r'^CrashReportClient\.exe$',
r'^dotnet\.exe$',
Expand Down