Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Add launch function to call launch_subprocess only if multiprocessing is actually necessary #4237

Merged
merged 5 commits into from
Jan 24, 2025

Conversation

qwint
Copy link
Collaborator

@qwint qwint commented Nov 24, 2024

What is this fixing or adding?

alternative to #3633 and making all clients that want similar handle it themselves

skips opening a new process if kivy (and thus the launcher gui) hasn't been loaded so stdin can function as expected on --nogui and similar

if there's a cleaner way to do this (even with a launcher rewrite) we should probably do that instead, but components seem pretty intentionally agnostic to if they're launched from the component arg handling or gui so I didn't really want to change that Found a Util function to do the kivy check lol

How was this tested?

opened text client and bizhawk client with --nogui and could type commands just fine
opened launcher GUI and could open text client and close launcher without issue
launched messenger from url and could open text client from the popup and close the popup without issues

If this makes graphical changes, please attach screenshots.

… been loaded so stdin can function as expected on --nogui and similar
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Nov 24, 2024
@Exempt-Medic Exempt-Medic added the is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. label Nov 25, 2024
Copy link
Contributor

@silasary silasary left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Contributor

@Jouramie Jouramie left a comment

Choose a reason for hiding this comment

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

Not tested, code LGTM.

@BadMagic100 BadMagic100 added waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer. and removed waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Jan 10, 2025
@black-sliver
Copy link
Member

I'm a bit worried about the naming. Does anyone have problems with keeping a technically-wrong name for this new behaviour?

@qwint
Copy link
Collaborator Author

qwint commented Jan 17, 2025

to repeat what I mentioned in discord,
I have no qualms about making this a new function and keeping the existing one's functionality intact,
I just doubt that the many if not all uses of the current function intended to always spawn a subprocess and believe they instead just use it because it's the wrapper you use when launching a client from the launcher (in which case the change will be welcome)

@Berserker66
Copy link
Member

I also dislike functions lieing to me.

@qwint qwint changed the title Core: Have launch_subprocess check if multiprocessing is actually necessary Core: Add launch function to call launch_subprocess only if multiprocessing is actually necessary Jan 23, 2025
@black-sliver
Copy link
Member

Was about to merge this, but I just realized that this now adds a function with wrong typing.

For one, this is missing typing for Callable, which is not a simple problem to solve - if args was an unpacked TypeVarTuple, i.e.

Ts = TypeVarTuple("Ts")

def launch(f: Callable[[*Ts], Any], args: Tuple[*Ts] = ()) -> None:
    f(*args)

, the default = () would be invalid.

Also there may be components that pass in a list[str] or a runtime-defined tuple rather than a fixed tuple?
So maybe we merge as-is and solve this in the future?

The other thing, which we should fix, is the type of name. name: str = None is invalid and should be str | None.

@silasary
Copy link
Contributor

For now, I'd lean towards merging as-is or with Callable[..., Any] (Which is functionally identical, but looks nicer).

The Type Hint isn't wrong, it's just less useful than it could be.

@black-sliver
Copy link
Member

The thing about bare Callable is that is is underspecified, which is similar to being untyped, but has its own error in mypy --strict.

So changing it to [..., Any] would be better, but this still can not check the call that is being made in the body.
I.e. it will assume that it can pass in any arguments even if that's not the case. (We know that we pass strings or nothing, but it happly accepts a function that takes only ints and doesnt check in the line that does the call, making it effectively untyped)

@qwint
Copy link
Collaborator Author

qwint commented Jan 24, 2025

Bare callable is what launch_subprocess already used, if we want to fix both while we're here I have no issue applying whatever typing you land on, but blocking this over using typing we already use somewhere else seems silly
fixed the str=None typing anyways because that's easy

@black-sliver
Copy link
Member

black-sliver commented Jan 24, 2025

blocking this over using typing we already use somewhere else seems silly

This is how typing goes to sh!* 😁

The name was "critical" since it's a real error even with lax settings. The other one is just missing typing, basically. Partially-typed functions are not great, but we don't require full typing, so this can be solved later.

Gonna review when i'm at PC.

Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

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

Change should be safe since it's opt-in now. Tested CommonClient from button, command line, with and without --nogui and it behaves correctly.

Thanks!

@black-sliver black-sliver merged commit 7474c27 into ArchipelagoMW:main Jan 24, 2025
16 checks passed
@qwint qwint deleted the launcher_skip_subprocess branch January 24, 2025 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. waiting-on: core-review Issue/PR has been peer-reviewed and is ready to be merged or needs input from a core maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants