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

Generalize .runBackground to work with all kinds of subprocesses #657

Closed
lihaoyi-databricks opened this issue Jul 11, 2019 · 4 comments · Fixed by #4085
Closed

Generalize .runBackground to work with all kinds of subprocesses #657

lihaoyi-databricks opened this issue Jul 11, 2019 · 4 comments · Fixed by #4085
Milestone

Comments

@lihaoyi-databricks
Copy link
Contributor

Currently it's hardcoded to only work for the main method of Java/Scala modules, but it could be useful for running other sorts of long-running daemons too: webpack proxy, docker run, databases, etc.

We might need to replace the auto-shutdown thread with a auto-shutdown subprocess, since we'll be running non-JVM things

@lihaoyi
Copy link
Member

lihaoyi commented Jul 24, 2019

Maybe could even make it a general-purpose wrapper that works with all kinds of Tasks as well

@lihaoyi
Copy link
Member

lihaoyi commented Dec 8, 2024

We've hit the need for a non-JVM runBackground now that we're aiming to support Javascript https://github.com/com-lihaoyi/mill/pull/4022/files and Python #3928.

@himanshumahajan138
Copy link
Contributor

@lihaoyi actually yesterday i was working on this same issue for web examples and i was mimicing the same code as we have for java/scala like having backgroundwrapper in .py extension and then run that file with all the necessary args.

I will pull a request for this in some time and i think untill we don't get general support we can go with this one

Your thoughts?

@lihaoyi
Copy link
Member

lihaoyi commented Dec 8, 2024

@himanshumahajan138 I think it should be doable to generalize MillBackgroundWrapper to wrap a subprocess, lemme try and implement that

lihaoyi added a commit that referenced this issue Dec 9, 2024
…4085)

Fixes #657

We re-use `MillBackgroundWrapper` and extend it to optionally spawn
subprocess instead of calling the in-process main method. There's a bit
of overhead in the JVM wrapper, but we need some kind of process wrapper
to manage the mutex and termination even when the Mill process
terminates, and eventually when
#4007 lands we can use that to
provide lighter-weight wrappers. We add a shutdown hook and copy the
termination grace-period logic from OS-Lib to try and gently kill the
wrapped process when necessary

Integrated this into `PythonModule#runBackground` and added a unit test
to verify the asynchronous launch, background existence (by checking
that a file lock is taken) and termination on deletion. We can integrate
this into `TypescriptModule` as well but punting that for later

The subprocess APIs are a mess but leaving that to fix in 0.13.0
#3772
@lefou lefou added this to the 0.12.4 milestone Dec 9, 2024
jodersky pushed a commit to jodersky/mill that referenced this issue Jan 14, 2025
…om-lihaoyi#4085)

Fixes com-lihaoyi#657

We re-use `MillBackgroundWrapper` and extend it to optionally spawn
subprocess instead of calling the in-process main method. There's a bit
of overhead in the JVM wrapper, but we need some kind of process wrapper
to manage the mutex and termination even when the Mill process
terminates, and eventually when
com-lihaoyi#4007 lands we can use that to
provide lighter-weight wrappers. We add a shutdown hook and copy the
termination grace-period logic from OS-Lib to try and gently kill the
wrapped process when necessary

Integrated this into `PythonModule#runBackground` and added a unit test
to verify the asynchronous launch, background existence (by checking
that a file lock is taken) and termination on deletion. We can integrate
this into `TypescriptModule` as well but punting that for later

The subprocess APIs are a mess but leaving that to fix in 0.13.0
com-lihaoyi#3772
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 a pull request may close this issue.

4 participants