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
+ #
4
14
5
15
6
16
"""
12
22
Monkeypatch Pool iterators so that Ctrl-C interrupts everything properly
13
23
derived from https://gist.github.com/aljungberg/626518
14
24
25
+
15
26
Copyright (c) Alexander Ljungberg. All rights reserved.
16
27
Modifications Copyright (c) nexB Inc. and others. All rights reserved.
17
28
36
47
"""
37
48
38
49
50
+
51
+ from multiprocessing import pool
52
+ from multiprocessing import TimeoutError
53
+
54
+
55
+
56
+ class ScanCodeTimeoutError (Exception ):
57
+ pass
58
+
59
+
39
60
def wrapped (func ):
40
61
"""
41
62
Ensure that we have a default timeout in all cases.
@@ -49,7 +70,11 @@ def wrapped(func):
49
70
if func .__name__ != 'wrap' :
50
71
51
72
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
53
78
54
79
return wrap
55
80
else :
0 commit comments