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"""
1222Monkeypatch Pool iterators so that Ctrl-C interrupts everything properly
1323derived from https://gist.github.com/aljungberg/626518
1424
25+
1526Copyright (c) Alexander Ljungberg. All rights reserved.
1627Modifications Copyright (c) nexB Inc. and others. All rights reserved.
1728
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+
3960def 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