Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions src/scancode/interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ def handler(signum, frame):
raise TimeoutError

try:
create_signal(SIGALRM, handler)
setitimer(ITIMER_REAL, timeout)
# We try to setup the signal. If we are not in the main thread
# this will raise a ValueError. In this case we just run the
# function without timeout.
try:
create_signal(SIGALRM, handler)
setitimer(ITIMER_REAL, timeout)
except ValueError:
pass

return NO_ERROR, func(*(args or ()), **(kwargs or {}))

except TimeoutError:
Expand All @@ -97,7 +104,10 @@ def handler(signum, frame):
return ERROR_MSG + traceback_format_exc(), NO_VALUE

finally:
setitimer(ITIMER_REAL, 0)
try:
setitimer(ITIMER_REAL, 0)
except ValueError:
pass

elif on_windows:
"""
Expand Down Expand Up @@ -191,4 +201,4 @@ def fake_interruptible(func, args=None, kwargs=None, timeout=DEFAULT_TIMEOUT):
try:
return NO_ERROR, func(*(args or ()), **(kwargs or {}))
except Exception:
return ERROR_MSG + traceback_format_exc(), NO_VALUE
return ERROR_MSG + traceback_format_exc(), NO_VALUE
9 changes: 8 additions & 1 deletion src/summarycode/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ def get_declared_holders(codebase, holders_tallies):
if entry['holder']
}
unique_key_file_holders = unique(entry_by_key_file_holders.keys())

# FIX: Added 'if holder in entry_by_holders' to prevent crash if a holder
# exists in key files but was filtered out of the main tallies (0 byte count)
unique_key_file_holders_entries = [
entry_by_holders[holder] for holder in unique_key_file_holders
if holder in entry_by_holders
]

holder_by_counts = defaultdict(list)
Expand All @@ -195,7 +199,10 @@ def get_declared_holders(codebase, holders_tallies):
# If we could not determine a holder, then we return a list of all the
# unique key file holders
if not declared_holders:
declared_holders = [entry['value'] for entry in unique_key_file_holders_entries]
# We must also filter here to avoid crashing on missing entries
declared_holders = [
entry['value'] for entry in unique_key_file_holders_entries
]

return declared_holders

Expand Down
Loading