KEMBAR78
Add more multiprocessing function stubs by khyox · Pull Request #1435 · python/typeshed · GitHub
Skip to content

Conversation

@khyox
Copy link
Contributor

@khyox khyox commented Jun 25, 2017

This target issue #1422 but also other related functions. The functions are those that multiprocessing init is inserting in globals from context.DefaultContext(BaseContext) and listed in the multiprocessing docs.

khyox added 2 commits June 25, 2017 05:12
This target issue python#1422 but also other related functions. The functions are those that cpython/Lib/multiprocessing/__init__.py is getting from DefaultContext(BaseContext) and listed in https://docs.python.org/3.6/library/multiprocessing.html#miscellaneous.

# ----- multiprocessing function stubs -----
def active_children() -> List[Process]: ...
def allow_connection_pickling() -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undocumented and apparently does nothing in 3.6. I suppose there's little harm in including it though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm keeping it then.

def get_all_start_methods() -> List[str]: ...
def get_context(method: Optional[str] = ...) -> BaseContext: ...
def get_logger() -> Logger: ...
def get_start_method(allow_none: Optional[bool] = ...) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one (as well as get_all_start_methods and get_context) doesn't exist in Python 2.

Also, judging from the documentation allow_none should just be a bool in Python 3, and the return type should be Optional[str].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Thanks!

def get_context(method: Optional[str] = ...) -> BaseContext: ...
def get_logger() -> Logger: ...
def get_start_method(allow_none: Optional[bool] = ...) -> str: ...
def log_to_stderr(level: Optional[str] = ...) -> Logger: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the level can also be an int, since it just gets passed to setLevel in logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Moving level to Optional[Union[str, int]].

def get_start_method(allow_none: Optional[bool] = ...) -> str: ...
def log_to_stderr(level: Optional[str] = ...) -> Logger: ...
def Manager() -> SyncManager: ...
def set_executable(executable: str) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one only exists on Windows, and sometimes on Unix after 3.4.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

def Manager() -> SyncManager: ...
def set_executable(executable: str) -> None: ...
def set_forkserver_preload(module_names: List[str]) -> None: ...
def set_start_method(method: Optional[str] = ...) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only after 3.4, and it doesn't look like the method is Optional.

There is also an undocumented force: bool = ... argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! On the one hand, it seems that method argument is optional and the undocumented force one is not present just in set_start_method of BaseContext in 3.4. On the other hand, it is overridden (with method not optional and the force optional) in DefaultContext, which seems to contain the imported method from __init__.py. Anyway, this is solved >=3.5 and both the latter signature.

Should stub for set_start_method of BaseContext in multiprocessing/context.pyi (line 94) be corrected with these changes? I mean to be like set_start_method of DefaultContext but for >=3.5.

@JelleZijlstra JelleZijlstra merged commit 61154a9 into python:master Jul 1, 2017
@khyox khyox deleted the patch-1 branch July 1, 2017 09:33
rhysparry added a commit to rhysparry/typeshed that referenced this pull request Jul 3, 2017
* python/master:
  Added stub for toaiff module (python#1455)
  Added stub for user module (python#1454)
  Add more multiprocessing function stubs (python#1435)
  PyYaml: uncomment commented out imports and add missing classmethod decorators (python#1439)
  Allow `os.readlink` to accept path-like objects (python#1441)
  Support named attributes in `os.uname()` result (python#1445)
  Fix signature for slite3.fetchmany (python#1444)
  Add __name__ field to MethodType (python#1442)
  Add TypedDict total argument (python#1443)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants