Feature Proposal: Session Reloading #466
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds (relatively basic) functionality to reload the current session in order to bring any new file changes without having to exit and re-launch PsySH. This is accomplished by replacing the current process with an identical one using
pcntl_exec
, automatically reloading files and accounting for any changes (see demonstration below).Caveats
Because this is a relatively basic implementation of reloading, there are a few caveats that I think are important to mention (and would love any feedback or suggestions to work around them).
Stateless Reloads
While this reload method will account for any file changes, what it doesn't do is persist the current state, meaning that any methods defined prior to a
reload
will be forgotten.Because of this,
reload
may not be the most appropriate command name, so if there are any suggestions for something that better reflects what is happening when the command is run I would love to hear them (refresh
maybe?).PCNTL Required
Because this command utilizes
pcntl_exec
to safely replace the current process with a new one, PCNTL is required. While this isn't necessarily a complication (it is a recommend extension, after all), there doesn't seem to be an established convention for commands that rely on optional dependencies.I would love any thoughts on how to best handle this. As it stands, the current implementation puts a note in the command help text, and throws an exception on execution if
pcntl_exec
isn't available, however disabling the command altogether when it isn't available might be more desirable.Demonstration
Relevant Issues: