Powershell gets stuck while running Foreach-Parallel

Answered Powershell gets stuck while running Foreach-Parallel

  • Wednesday, January 23, 2013 7:58 PM
     
     

    I'm trying to use Foreach-Parallel to execute some long running tasks in parallel. I'm using Powershell V2 on Windows Server 2008 R2. What I'm finding is that the script will periodically get "stuck" and not do anything at all for hours at a time (even the subtasks are not executing), but once I press ctrl+c it will continue on its merry way. Does anyone know what might be going on here, why ctrl+c would alleviate the problem and if there's any way to fix this?

    I vaguely remember seeing this in the past when using ps jobs as well.

All Replies

  • Wednesday, January 23, 2013 8:16 PM
    Moderator
     
     

    Hi,

    We didn't write that script. Please use the Q&A tab for that script's entry in the repository to ask questions about it.

    Bill

  • Wednesday, January 23, 2013 8:24 PM
     
     
    Fair enough, I was asking more from the perspective of powershell in general. i.e., what does ctrl+c actually do to a powershell console and why would it cause a process that was previously stuck (i.e. background jobs using Start-Job) to become unstuck? 
  • Wednesday, January 23, 2013 8:38 PM
    Moderator
     
     

    In a Windows console session, Ctrl+C usually cancels or terminates the currently running activity.

    Bill

  • Wednesday, January 23, 2013 8:38 PM
     
     Answered
    Fair enough, I was asking more from the perspective of powershell in general. i.e., what does ctrl+c actually do to a powershell console and why would it cause a process that was previously stuck (i.e. background jobs using Start-Job) to become unstuck? 

    Ctrl-C kills the current foreground process.

    You are likely exceeding you resources.  You cannot generate unlimited background processes.  The script looks to be PosH 1.0 where there were no jobs.  In PosH V2 and later use jobs and use Invoke.  You can control the number of concurrent jobs.

    Consider using WorkFlows as parallelism is better controlled.


    ¯\_(ツ)_/¯