Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
e181ba75
Commit
e181ba75
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
add `monkey_patch_parallel_compilation`
parent
f81298c8
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
docs/distutils.rst
+5
-0
5 additions, 0 deletions
docs/distutils.rst
docs/index.rst
+1
-0
1 addition, 0 deletions
docs/index.rst
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/distutils.py
+43
-0
43 additions, 0 deletions
satella/distutils.py
with
51 additions
and
1 deletion
CHANGELOG.md
+
1
−
0
View file @
e181ba75
...
@@ -3,3 +3,4 @@
...
@@ -3,3 +3,4 @@
*
added
`write_json_to_file`
*
added
`write_json_to_file`
*
added
`read_json_from_file`
*
added
`read_json_from_file`
*
added
`write_json_to_file_if_different`
*
added
`write_json_to_file_if_different`
*
added
`satella.distutils`
This diff is collapsed.
Click to expand it.
docs/distutils.rst
0 → 100644
+
5
−
0
View file @
e181ba75
Distutils extensions
====================
.. autofunction:: satella.distutils.monkey_patch_parallel_compilation
This diff is collapsed.
Click to expand it.
docs/index.rst
+
1
−
0
View file @
e181ba75
...
@@ -38,6 +38,7 @@ Visit the project's page at GitHub_!
...
@@ -38,6 +38,7 @@ Visit the project's page at GitHub_!
processes
processes
cassandra
cassandra
opentracing
opentracing
distutils
Indices and tables
Indices and tables
...
...
This diff is collapsed.
Click to expand it.
satella/__init__.py
+
1
−
1
View file @
e181ba75
__version__
=
'
2.14.23_a
2
'
__version__
=
'
2.14.23_a
3
'
This diff is collapsed.
Click to expand it.
satella/distutils.py
0 → 100644
+
43
−
0
View file @
e181ba75
import
typing
as
tp
import
multiprocessing
__all__
=
[
'
monkey_patch_parallel_compilation
'
]
def
monkey_patch_parallel_compilation
(
cores
:
tp
.
Optional
[
int
]
=
None
):
"""
This monkey-patches distutils to provide parallel compilation, even if you have
a single extension built from multiple .c files.
Invoke in your setup.py file
:param cores: amount of cores. Leave at default (None) for autodetection.
"""
if
cores
is
None
:
cores
=
multiprocessing
.
cpu_count
()
# monkey-patch for parallel compilation
def
parallelCCompile
(
self
,
sources
,
output_dir
=
None
,
macros
=
None
,
include_dirs
=
None
,
debug
=
0
,
extra_preargs
=
None
,
extra_postargs
=
None
,
depends
=
None
):
# those lines are copied from distutils.ccompiler.CCompiler directly
macros
,
objects
,
extra_postargs
,
pp_opts
,
build
=
self
.
_setup_compile
(
output_dir
,
macros
,
include_dirs
,
sources
,
depends
,
extra_postargs
)
cc_args
=
self
.
_get_cc_args
(
pp_opts
,
debug
,
extra_preargs
)
# parallel code
N
=
2
# number of parallel compilations
import
multiprocessing.pool
def
_single_compile
(
obj
):
try
:
src
,
ext
=
build
[
obj
]
except
KeyError
:
return
self
.
_compile
(
obj
,
src
,
ext
,
cc_args
,
extra_postargs
,
pp_opts
)
# convert to list, imap is evaluated on-demand
list
(
multiprocessing
.
pool
.
ThreadPool
(
cores
).
imap
(
_single_compile
,
objects
))
return
objects
import
distutils.ccompiler
distutils
.
ccompiler
.
CCompiler
.
compile
=
parallelCCompile
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment