Jaykul / Jupyter-PowerShell

Jupyter Kernel for PowerShell
Other
110 stars 17 forks source link

Job related exception #20

Closed markekraus closed 6 years ago

markekraus commented 6 years ago

I'm trying run the following code blocks

@(
    Start-Job {Start-sleep -Seconds 2; Get-Date}
    Start-Job {Start-sleep -Seconds 3; Get-Date}
) | Wait-Job | Receive-Job
$Jobs = @(
    Start-Job {Start-sleep -Seconds 2; Get-Date}
    Start-Job {Start-sleep -Seconds 3; Get-Date}
) 
$Jobs | Wait-Job | Receive-Job
$Job1 = Start-Job {Start-sleep -Seconds 2; Get-Date}
$Job2 = Start-Job {Start-sleep -Seconds 3; Get-Date}
Start-sleep -Seconds 5
Get-Job | Receive-Job

Or any kind of combination to start a job and receive it. I get the following exception for all of them:

PowerShell-Kernel : Object reference not set to an instance of an object.

   at Jupyter.PowerShell.PowerShellEngine.LogErrors(ExecutionResult result, PipelineReader`1 errorStream) in C:\Users\Joel\Projects\Jupyter\Jupyter-PowerShell\Source\PowerShell-Kernel\PowerShellEngine.cs:line 179
   at Jupyter.PowerShell.PowerShellEngine.Execute(String script) in C:\Users\Joel\Projects\Jupyter\Jupyter-PowerShell\Source\PowerShell-Kernel\PowerShellEngine.cs:line 75

Note: My purpose for using jobs in the jupyter notebook was to demonstrate different methods of parallel and concurrent programming in PowerShell with pretty markdown all around it. Not trying to do anything real fancy.

markekraus commented 6 years ago

did some digging on the jobs.. not much helpful there.

$Job1 | fl * -force
$Job1.ChildJobs[0] | fl * -force
State         : Failed
HasMoreData   : False
StatusMessage : 
Location      : localhost
Command       : Start-sleep -Seconds 2; Get-Date
JobStateInfo  : Failed
Finished      : System.Threading.ManualResetEvent
InstanceId    : a5e30a71-f698-47a3-b2ff-ea3a357d0dd1
Id            : 57
Name          : Job57
ChildJobs     : {Job58}
PSBeginTime   : 5/5/2018 12:16:08 PM
PSEndTime     : 5/5/2018 12:16:08 PM
PSJobTypeName : BackgroundJob
Output        : {}
Error         : {}
Progress      : {}
Verbose       : {}
Debug         : {}
Warning       : {}
Information   : {}

State         : Failed
StatusMessage : 
HasMoreData   : False
Location      : localhost
Runspace      : System.Management.Automation.RemoteRunspace
Debugger      : 
IsAsync       : True
Command       : Start-sleep -Seconds 2; Get-Date
JobStateInfo  : Failed
Finished      : System.Threading.ManualResetEvent
InstanceId    : f498e7e1-d009-4b53-98b6-460ed27afa9b
Id            : 58
Name          : Job58
ChildJobs     : {}
PSBeginTime   : 
PSEndTime     : 5/5/2018 12:16:08 PM
PSJobTypeName : 
Output        : {}
Error         : {}
Progress      : {}
Verbose       : {}
Debug         : {}
Warning       : {}
Information   : {}

The errors look more helpful

$err = $error[0]
$err | fl * -force
$err.exception | fl * -force
writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.Management.Automation.Remoting.PSRemotingTransportException: An error occurred while 
                        starting the background process. Error reported: The system cannot find the file specified. 
                        ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
                           at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
                           at System.Diagnostics.Process.Start()
                           at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
                           at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManager.Cre
                        ateAsync()
                           --- End of inner exception stack trace ---
TargetObject          : localhost
CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
FullyQualifiedErrorId : -2147467259,PSSessionStateBroken
ErrorDetails          : [localhost] An error occurred while starting the background process. Error reported: The system 
                        cannot find the file specified.
InvocationInfo        : 
ScriptStackTrace      : 
PipelineIterationInfo : {}

ErrorCode                   : -2147467259
TransportMessage            : 
ErrorRecord                 : An error occurred while starting the background process. Error reported: The system 
                              cannot find the file specified.
WasThrownFromThrowStatement : False
Message                     : An error occurred while starting the background process. Error reported: The system 
                              cannot find the file specified.
Data                        : {}
InnerException              : System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file 
                              specified
                                 at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
                                 at System.Diagnostics.Process.Start()
                                 at System.Management.Automation.Runspaces.PowerShellProcessInstance.Start()
                                 at System.Management.Automation.Remoting.Client.OutOfProcessClientSessionTransportManag
                              er.CreateAsync()
TargetSite                  : 
StackTrace                  : 
HelpLink                    : 
Source                      : 
HResult                     : -2146233087
Jaykul commented 6 years ago

Looks like I would have to ship the actual pwsh executable for this to work.

Since the licensing situation for that is fraught with peril I'm frankly very annoyed.

markekraus commented 6 years ago

This appears to be an upstream issue PowerShell/PowerShell#7052 closing