Skip to content

Commit

Permalink
Prevent unwanted multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Nov 5, 2023
1 parent 484965f commit cedb148
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4666,17 +4666,17 @@ Can optionally be called to warm up the compiler and get it ready for parsing. P

#### `cmd`

**coconut.api.cmd**(_args_=`None`, *, _argv_=`None`, _interact_=`False`, _default\_target_=`None`, _state_=`False`)
**coconut.api.cmd**(_args_=`None`, *, _argv_=`None`, _interact_=`False`, _default\_target_=`None`, _default\_jobs_=`None`, _state_=`False`)

Executes the given _args_ as if they were fed to `coconut` on the command-line, with the exception that unless _interact_ is true or `-i` is passed, the interpreter will not be started. Additionally, _argv_ can be used to pass in arguments as in `--argv` and _default\_target_ can be used to set the default `--target`.

Has the same effect of setting the command-line flags on the given _state_ object as `setup` (with the global `state` object used when _state_ is `False`).

#### `cmd_sys`

**coconut.api.cmd_sys**(_args_=`None`, *, _argv_=`None`, _interact_=`False`, _default\_target_=`"sys"`, _state_=`False`)
**coconut.api.cmd_sys**(_args_=`None`, *, _argv_=`None`, _interact_=`False`, _default\_target_=`"sys"`, _default\_jobs_=`"0"`, _state_=`False`)

Same as `coconut.api.cmd` but _default\_target_ is `"sys"` rather than `None` (universal).
Same as `coconut.api.cmd` but _default\_target_ is `"sys"` rather than `None` (universal) and _default\_jobs_=`"0"` rather than `None` (`"sys"`)`.

#### `coconut_exec`

Expand Down
1 change: 1 addition & 0 deletions coconut/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def cmd(
argv: Iterable[Text] | None = None,
interact: bool = False,
default_target: Text | None = None,
default_jobs: Text | None = None,
) -> None:
"""Process command-line arguments."""
...
Expand Down
4 changes: 2 additions & 2 deletions coconut/command/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
vi_mode_env_var,
prompt_vi_mode,
py_version_str,
default_jobs,
base_default_jobs,
)

# -----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -193,7 +193,7 @@
"-j", "--jobs",
metavar="processes",
type=str,
help="number of additional processes to use (defaults to " + ascii(default_jobs) + ") (0 is no additional processes; 'sys' uses machine default)",
help="number of additional processes to use (defaults to " + ascii(base_default_jobs) + ") (0 is no additional processes; 'sys' uses machine default)",
)

arguments.add_argument(
Expand Down
8 changes: 5 additions & 3 deletions coconut/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
coconut_pth_file,
error_color_code,
jupyter_console_commands,
default_jobs,
base_default_jobs,
create_package_retries,
default_use_cache_dir,
coconut_cache_dir,
Expand Down Expand Up @@ -176,7 +176,7 @@ def cmd_sys(self, *args, **in_kwargs):
return self.cmd(*args, **out_kwargs)

# new external parameters should be updated in api.pyi and DOCS
def cmd(self, args=None, argv=None, interact=True, default_target=None, use_dest=None):
def cmd(self, args=None, argv=None, interact=True, default_target=None, default_jobs=None, use_dest=None):
"""Process command-line arguments."""
result = None
with self.handling_exceptions():
Expand All @@ -190,6 +190,8 @@ def cmd(self, args=None, argv=None, interact=True, default_target=None, use_dest
parsed_args.argv = argv
if parsed_args.target is None:
parsed_args.target = default_target
if parsed_args.jobs is None:
parsed_args.jobs = default_jobs
if use_dest is not None and not parsed_args.no_write:
internal_assert(parsed_args.dest is None, "coconut-run got passed a dest", parsed_args)
parsed_args.dest = use_dest
Expand Down Expand Up @@ -706,7 +708,7 @@ def disable_jobs(self):

def get_max_workers(self):
"""Get the max_workers to use for creating ProcessPoolExecutor."""
jobs = self.jobs if self.jobs is not None else default_jobs
jobs = self.jobs if self.jobs is not None else base_default_jobs
if jobs == "sys":
return None
else:
Expand Down
4 changes: 2 additions & 2 deletions coconut/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def get_path_env_var(env_var, default):
# always use atomic --xxx=yyy rather than --xxx yyy
# and don't include --run, --quiet, or --target as they're added separately
coconut_base_run_args = ("--keep-lines",)
coconut_sys_kwargs = dict(default_target="sys") # passed to Command.cmd
coconut_sys_kwargs = dict(default_target="sys", default_jobs="0") # passed to Command.cmd

default_mypy_args = (
"--pretty",
Expand Down Expand Up @@ -701,7 +701,7 @@ def get_path_env_var(env_var, default):
kilobyte = 1024
min_stack_size_kbs = 160

default_jobs = "sys" if not PY26 else 0
base_default_jobs = "sys" if not PY26 else 0

mypy_install_arg = "install"
jupyter_install_arg = "install"
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.0.3"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 20
DEVELOP = 21
ALPHA = False # for pre releases rather than post releases

assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"
Expand Down

0 comments on commit cedb148

Please sign in to comment.