Repository navigation
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime
Description
It seems like it should be possible to subscribe to Runspace.AvailabilityChanged and Runspace.StateChanged to wait for a runspace to be opened when using Runspace.OpenAsync(). However, I have not found a way to use those events in a manner that reliably waits until the opening process is complete.
Specifically, I am surprised that the runspace transitions to Available,Opened then Busy,Opened before it completes the import of modules specified by InitialSessionState. It seems like neither the Opened nor Available states should be reached until the module is imported.
Steps to reproduce
$moduleContent = {
function fibonacci {
param([int]$n)
[bigint]$a=0
[bigint]$b=1
foreach ($x in 0..$n)
{
$a,$b = $b,($a+$b)
}
$b
}
0..0 | % { fibonacci 5000 }
}
$modulePath = "$([System.IO.Path]::GetTempPath())slowLoading.psm1"
$moduleContent | Set-Content $modulePath
$initialSessionState = [initialsessionstate]::CreateDefault()
$initialSessionState.ImportPSModule($modulePath)
$runspace = [runspacefactory]::CreateRunspace($initialSessionState)
$runspace.OpenAsync()
1..500 |
% {
[pscustomobject]@{
i = $_
Available = $runspace.RunspaceAvailability
State = $runspace.RunspaceStateInfo.State
}
sleep 0.5
}Expected behavior
i Available State
- --------- -----
1 None Opening
...
8 None Opening
9 Busy Opening
...
285 Busy Opening
286 Available Opened
Actual behavior
i Available State
- --------- -----
1 None Opening
...
8 None Opening
9 Available Opened
10 Available Opened
11 Busy Opened
...
285 Busy Opened
286 Available Opened
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0-preview.691
PSEdition Core
GitCommitId v6.1.0-preview.691
OS Microsoft Windows 6.3.9600
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime
Activity
alx9r commentedon Jun 15, 2018
FWIW it seems like pattern matching on a merged stream of
RunspaceAvailabilityChangedandStateChangedevents can be used to infer when a runspace is ready for use. There seems to be two characteristic streams depending on whether modules are specified inInitialSessionState.Modules.The characteristic event streams seem to be as shown below. The last event mentioned in the respective stream seems to indicate that the runspace is ready for use.
I don't know how robust this method is, but it's the best method I have found for getting a signal when a runspace is ready for use. I've also found that having such a signal is critical for achieving speedup by utilizing multiple processors when executing CPU-bound PowerShell.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.