-
-
Notifications
You must be signed in to change notification settings - Fork 65
Add ForkContext #212
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
base: 2.x
Are you sure you want to change the base?
Add ForkContext #212
Conversation
This does not work in psalm, because |
Additionally, I added some extra error handling logic to handle segfaults in child processes (commonly caused by JIT usage in psalm), would love to see that in this impl as well: https://github.com/vimeo/psalm/blob/fc437245b15a7220de107bc191a3559fdbf94595/src/Psalm/Internal/Fork/ForkContext.php#L61 |
|
My local test was running from {main}, so I missed that. Unfortunately running this new context through the usual test suite crashes and burns, of course because we're forking the test process. I removed the event loop queuing from |
What is the use case you mentioned? |
@danog Can you please elaborate on how you're using this in Psalm? |
I'm using this in psalm to avoid serializing and sending tens of megabytes of data structures containing information about the codebase post-scanning, when starting the analysis phase. |
https://github.com/danog/parallel/tree/fork-context contains some more improvements and enables (most) unit tests, working OK in Psalm! |
Ping @trowski :) |
* Skip another test * cs-fix
src/Context/ForkContext.php
Outdated
public static function isSupported(): bool | ||
{ | ||
return \function_exists('pcntl_fork') | ||
&& !EventLoop::getDriver() instanceof UvDriver; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs say it's not compatible with extension based event loops, but we only check for UV here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this needs fixing, @trowski mind bumping
Serializer $serializer = new NativeSerializer(), | ||
): void { | ||
/** @noinspection PhpUnusedLocalVariableInspection */ | ||
$argc = \count($argv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this code change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The call to
EventLoop::run()
was removed because the event loop is already running when called fromForkContext
- Added the ability to pass a particular serializer instance, also used in
ForkContext
.
|
||
public function testImmediateJoin(): void | ||
{ | ||
// tmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danog This was copied from your code, can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have a clear explanation for these specific failures yet, but the current state is better than the initial state of the PR which completely disabled tests
This adds a
Context
implementation which usespcntl_fork
to create another process. This is a strategy which we abandoned some time ago due to the issues with copying parent context into a child, however there are particular case where that behavior can be advantageous.This context is NOT added to
DefaultContextFactory
, and in fact has warnings against its use in the class docblock.@danog Can you please check if this works for you in Psalm.