Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
2100d87c
Commit
2100d87c
authored
Aug 14, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix KeyboardInterrupt handling when running cythonize() in parallel
parent
d5af12c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+20
-3
No files found.
Cython/Build/Dependencies.py
View file @
2100d87c
...
...
@@ -798,15 +798,24 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, fo
# Requires multiprocessing (or Python >= 2.6)
try
:
import
multiprocessing
pool
=
multiprocessing
.
Pool
(
nthreads
)
pool
=
multiprocessing
.
Pool
(
nthreads
,
initializer
=
_init_multiprocessing_helper
)
except
(
ImportError
,
OSError
):
print
(
"multiprocessing required for parallel cythonization"
)
nthreads
=
0
else
:
# This is a bit more involved than it should be, because KeyboardInterrupts
# break the multiprocessing workers when using a normal pool.map().
# See, for example:
# http://noswap.com/blog/python-multiprocessing-keyboardinterrupt
try
:
pool
.
map
(
cythonize_one_helper
,
to_compile
)
finally
:
result
=
pool
.
map_async
(
cythonize_one_helper
,
to_compile
,
chunksize
=
1
)
pool
.
close
()
while
not
result
.
ready
():
result
.
get
(
10
)
# seconds
except
KeyboardInterrupt
:
pool
.
terminate
()
pool
.
join
()
if
not
nthreads
:
for
args
in
to_compile
:
cythonize_one
(
*
args
[
1
:])
...
...
@@ -942,6 +951,7 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None, raise_on_f
finally
:
f
.
close
()
def
cythonize_one_helper
(
m
):
import
traceback
try
:
...
...
@@ -950,6 +960,13 @@ def cythonize_one_helper(m):
traceback
.
print_exc
()
raise
def
_init_multiprocessing_helper
():
# KeyboardInterrupt kills workers, so don't let them get it
import
signal
signal
.
signal
(
signal
.
SIGINT
,
signal
.
SIG_IGN
)
def
cleanup_cache
(
cache
,
target_size
,
ratio
=
.
85
):
try
:
p
=
subprocess
.
Popen
([
'du'
,
'-s'
,
'-k'
,
os
.
path
.
abspath
(
cache
)],
stdout
=
subprocess
.
PIPE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment