Skip to content

Commit 6252270

Browse files
committed
Fail correctly on timeout
Somehow we need to re-raise an exception fo this to work correctly Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 1c1acdc commit 6252270

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/scancode/pool.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
2-
3-
from multiprocessing import pool
1+
#
2+
# Copyright (c) Alexander Ljungberg. All rights reserved.
3+
# Modifications Copyright (c) nexB Inc. and others. All rights reserved.
4+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
5+
# The ScanCode software is licensed under the Apache License version 2.0.
6+
#
7+
# You may not use this software except in compliance with the License.
8+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
9+
# Unless required by applicable law or agreed to in writing, software distributed
10+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
# specific language governing permissions and limitations under the License.
13+
#
414

515

616
"""
@@ -12,6 +22,7 @@
1222
Monkeypatch Pool iterators so that Ctrl-C interrupts everything properly
1323
derived from https://gist.github.com/aljungberg/626518
1424
25+
1526
Copyright (c) Alexander Ljungberg. All rights reserved.
1627
Modifications Copyright (c) nexB Inc. and others. All rights reserved.
1728
@@ -36,6 +47,16 @@
3647
"""
3748

3849

50+
51+
from multiprocessing import pool
52+
from multiprocessing import TimeoutError
53+
54+
55+
56+
class ScanCodeTimeoutError(Exception):
57+
pass
58+
59+
3960
def wrapped(func):
4061
"""
4162
Ensure that we have a default timeout in all cases.
@@ -49,7 +70,11 @@ def wrapped(func):
4970
if func.__name__ != 'wrap':
5071

5172
def wrap(self, timeout=None):
52-
return func(self, timeout=timeout or 3600)
73+
try:
74+
result = func(self, timeout=timeout or 3600)
75+
except TimeoutError as te:
76+
raise ScanCodeTimeoutError() from te
77+
return result
5378

5479
return wrap
5580
else:

0 commit comments

Comments
 (0)