Package nz.org.riskscape.cpython
Class CPythonSpawner
java.lang.Object
nz.org.riskscape.cpython.CPythonSpawner
Handles spawning child CPython processes.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Simple class to help track child CPython processes that we spawn. -
Constructor Summary
ConstructorDescriptionCPythonSpawner
(CPythonSettings settings, nz.org.riskscape.problem.ProblemSink problemSink) -
Method Summary
Modifier and TypeMethodDescriptionvoid
A Non-blocking version of checkForOutputAndBlock.void
Blocks the calling thread until there's been a full loop of the reaper thread.void
destroy()
Destroys this spawner by stopping the reaper thread, killing all of the child processes and then waiting for the reaper to exit.void
killAll()
Forcibly destroy all the processes under our care.startWrapperScript
(Object errorContext, nz.org.riskscape.engine.resource.Resource userScript, String... scriptArgs) Starts cpython process that wraps a user's python script so that it can start accepting function calls
-
Constructor Details
-
CPythonSpawner
-
-
Method Details
-
startWrapperScript
public CPythonSpawner.CPythonProcess startWrapperScript(Object errorContext, nz.org.riskscape.engine.resource.Resource userScript, String... scriptArgs) Starts cpython process that wraps a user's python script so that it can start accepting function calls
- Parameters:
errorContext
- context for an error message.userScript
- the user's code to executescriptArgs
- arguments that get given to the script - these will get picked up by the adaptor script to prime the serialization
-
checkForOutputAndWait
public void checkForOutputAndWait()Blocks the calling thread until there's been a full loop of the reaper thread. This is a good way to ensure that any stderr output or processes have been reaped before doing something
-
checkForOutput
public void checkForOutput()A Non-blocking version of checkForOutputAndBlock. Wakes up the reaper thread, but doesn't wait for a check before returning
-
killAll
public void killAll()Forcibly destroy all the processes under our care.
-
destroy
public void destroy()Destroys this spawner by stopping the reaper thread, killing all of the child processes and then waiting for the reaper to exit. You can't use the spawner again.
-
getSettings
-