Skip to content

Commit e433a6c

Browse files
author
Staffan Gustafsson
committed
Fixing issues with reuse of runspaces
Grouped progress Variables PSParallelIndex and PSParallelProgressId available in the parallel runspaces Simplified interface by removing parameters to import things from invoking runspace. Use InitialSessionState instead.
1 parent dab8971 commit e433a6c

11 files changed

+162
-286
lines changed

module/PSParallel.psd1

234 Bytes
Binary file not shown.

module/en-US/PSParallel.dll-Help.xml

+2-128
Original file line numberDiff line numberDiff line change
@@ -66,90 +66,6 @@ ogress is being reported.</maml:para>
6666
<maml:name>ThrottleLimit</maml:name>
6767
<maml:description>
6868
<maml:para>Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this
69-
parameter or enter a value of 0, the default value, 16, is used.</maml:para>
70-
</maml:description>
71-
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
72-
</command:parameter>
73-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="imo">
74-
<maml:name>ImportModule</maml:name>
75-
<maml:description>
76-
<maml:para>Specify the names of the modules to import into the runspaces running the scriptblock to process.</maml:para>
77-
</maml:description>
78-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
79-
</command:parameter>
80-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="iva">
81-
<maml:name>ImportVariable</maml:name>
82-
<maml:description>
83-
<maml:para>Specifies the variables to import into the Runspaces running the specified ScriptBlock.
84-
85-
If not specified, all variables are imported.</maml:para>
86-
</maml:description>
87-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
88-
</command:parameter>
89-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="ifu">
90-
<maml:name>ImportFunction</maml:name>
91-
<maml:description>
92-
<maml:para>Specifies the functions to import into the Runspaces running the specified ScriptBlock.
93-
94-
It this variables isn&#39;t specified, all functions are imported.</maml:para>
95-
</maml:description>
96-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
97-
</command:parameter>
98-
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="named">
99-
<maml:name>InputObject</maml:name>
100-
<maml:description>
101-
<maml:para>Specifies the input objects. Invoke-Parallel runs the script block on each input object in parallel. Enter a variable th
102-
at contains the objects, or type a command or expression that gets the objects.</maml:para>
103-
</maml:description>
104-
<command:parameterValue required="true" variableLength="false">PSObject</command:parameterValue>
105-
</command:parameter>
106-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="">
107-
<maml:name>NoProgress</maml:name>
108-
<maml:description>
109-
<maml:para>Will not show progress from Invoke-Progress. Progress from the scriptblock will still be displayed.</maml:para>
110-
</maml:description>
111-
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
112-
<dev:defaultValue>
113-
</dev:defaultValue>
114-
</command:parameter>
115-
</command:syntaxItem>
116-
<command:syntaxItem>
117-
<maml:name>Invoke-Parallel</maml:name>
118-
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="0">
119-
<maml:name>ScriptBlock</maml:name>
120-
<maml:description>
121-
<maml:para>Specifies the operation that is performed on each input object. Enter a script block that describes the operation.</maml:para>
122-
</maml:description>
123-
<command:parameterValue required="true" variableLength="false">ScriptBlock</command:parameterValue>
124-
</command:parameter>
125-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="ppi">
126-
<maml:name>ParentProgressId</maml:name>
127-
<maml:description>
128-
<maml:para>Identifies the parent activity of the current activity. Use the value -1 if the current activity has no parent activity.</maml:para>
129-
</maml:description>
130-
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
131-
</command:parameter>
132-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="pi">
133-
<maml:name>ProgressId</maml:name>
134-
<maml:description>
135-
<maml:para>Specifies an ID that distinguishes each progress bar from the others. Use this parameter when you are creating more than
136-
one progress bar in a single command. If the progress bars do not have different IDs, they are superimposed instead of
137-
being displayed in a series.</maml:para>
138-
</maml:description>
139-
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
140-
</command:parameter>
141-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="pa">
142-
<maml:name>ProgressActivity</maml:name>
143-
<maml:description>
144-
<maml:para>Specifies the first line of progress text in the heading above the status bar. This text describes the activity whose pr
145-
ogress is being reported.</maml:para>
146-
</maml:description>
147-
<command:parameterValue required="false" variableLength="false">String</command:parameterValue>
148-
</command:parameter>
149-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
150-
<maml:name>ThrottleLimit</maml:name>
151-
<maml:description>
152-
<maml:para>Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this
15369
parameter or enter a value of 0, the default value, 16, is used.</maml:para>
15470
</maml:description>
15571
<command:parameterValue required="false" variableLength="false">Int32</command:parameterValue>
@@ -178,8 +94,7 @@ at contains the objects, or type a command or expression that gets the objects.<
17894
<maml:para>Will not show progress from Invoke-Progress. Progress from the scriptblock will still be displayed.</maml:para>
17995
</maml:description>
18096
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
181-
<dev:defaultValue>
182-
</dev:defaultValue>
97+
<dev:defaultValue/>
18398
</command:parameter>
18499
</command:syntaxItem>
185100
</command:syntax>
@@ -249,46 +164,6 @@ parameter or enter a value of 0, the default value, 16, is used.</maml:para>
249164
</dev:type>
250165
<dev:defaultValue/>
251166
</command:parameter>
252-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="imo">
253-
<maml:name>ImportModule</maml:name>
254-
<maml:description>
255-
<maml:para>Specify the names of the modules to import into the runspaces running the scriptblock to process.</maml:para>
256-
</maml:description>
257-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
258-
<dev:type>
259-
<maml:name>String[]</maml:name>
260-
<maml:uri/>
261-
</dev:type>
262-
<dev:defaultValue/>
263-
</command:parameter>
264-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="iva">
265-
<maml:name>ImportVariable</maml:name>
266-
<maml:description>
267-
<maml:para>Specifies the variables to import into the Runspaces running the specified ScriptBlock.
268-
269-
If not specified, all variables are imported.</maml:para>
270-
</maml:description>
271-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
272-
<dev:type>
273-
<maml:name>String[]</maml:name>
274-
<maml:uri/>
275-
</dev:type>
276-
<dev:defaultValue/>
277-
</command:parameter>
278-
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="ifu">
279-
<maml:name>ImportFunction</maml:name>
280-
<maml:description>
281-
<maml:para>Specifies the functions to import into the Runspaces running the specified ScriptBlock.
282-
283-
It this variables isn&#39;t specified, all functions are imported.</maml:para>
284-
</maml:description>
285-
<command:parameterValue required="false" variableLength="false">String[]</command:parameterValue>
286-
<dev:type>
287-
<maml:name>String[]</maml:name>
288-
<maml:uri/>
289-
</dev:type>
290-
<dev:defaultValue/>
291-
</command:parameter>
292167
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="True (ByValue)" position="named">
293168
<maml:name>InputObject</maml:name>
294169
<maml:description>
@@ -312,8 +187,7 @@ at contains the objects, or type a command or expression that gets the objects.<
312187
<maml:name>SwitchParameter</maml:name>
313188
<maml:uri/>
314189
</dev:type>
315-
<dev:defaultValue>
316-
</dev:defaultValue>
190+
<dev:defaultValue/>
317191
</command:parameter>
318192
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named" aliases="iss">
319193
<maml:name>InitialSessionState</maml:name>

scripts/Install.ps1

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
param([string]$InstallDirectory)
1+
$manPath = Get-ChildItem -recurse $PSScriptRoot/../module -include *.psd1 | select -first 1
2+
$man = Test-ModuleManifest $manPath
23

3-
$rootDir = Split-Path (Split-Path $MyInvocation.MyCommand.Path)
4+
$name = $man.Name
5+
[string]$version = $man.Version
6+
$moduleSourceDir = "$PSScriptRoot/$name"
7+
$moduleDir = "~/documents/WindowsPowerShell/Modules/$name/$version/"
8+
9+
[string]$rootDir = Resolve-Path $PSSCriptRoot/..
10+
11+
$InstallDirectory = $moduleDir
412

513
if ('' -eq $InstallDirectory)
614
{
@@ -46,5 +54,8 @@ $lang.Foreach{
4654

4755
Get-ChildItem -Recurse -Path $InstallDirectory
4856

49-
$cert = Get-Item Cert:\CurrentUser\My\98D6087848D1213F20149ADFE698473429A9B15D
50-
Get-ChildItem -File $InstallDirectory -Include *.dll,*.psd1 | Set-AuthenticodeSignature -Certificate $cert
57+
$cert =Get-ChildItem cert:\CurrentUser\My -CodeSigningCert
58+
if($cert)
59+
{
60+
Get-ChildItem -File $InstallDirectory -Include *.dll,*.psd1 -Recurse | Set-AuthenticodeSignature -Certificate $cert -TimestampServer http://timestamp.verisign.com/scripts/timstamp.dll
61+
}

scripts/Publish-ToGallery.ps1

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
$p = @{
22
Name = "PSParallel"
33
NuGetApiKey = $NuGetApiKey
4-
LicenseUri = "https://github.com/powercode/PSParallel/blob/master/LICENSE"
5-
IconUri = "https://github.com/powercode/PSParallel/blob/master/images/PSParallel_icon.png"
6-
Tag = "Parallel","Runspace","Invoke","Foreach"
7-
ReleaseNote = "Minor bugfixes"
8-
ProjectUri = "https://github.com/powercode/PSParallel"
94
}
105

116
Publish-Module @p

scripts/dbg.ps1

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
param(
2+
[int] $ThrottleLimit = 3,
3+
[int] $Milliseconds = 500
4+
)
5+
6+
function new-philosopher {
7+
param($name, [string[]] $treats)
8+
[PSCustomObject] @{
9+
Name = $name
10+
Treats = $treats
11+
}
12+
}
13+
14+
function new-philosopher {
15+
param($name, [string[]] $treats)
16+
[PSCustomObject] @{
17+
Name = $name
18+
Treats = $treats
19+
}
20+
}
21+
22+
$philosopherData = @(
23+
new-philosopher 'Immanuel Kant' 'was a real pissant','who where very rarely stable'
24+
new-philosopher 'Heidegger' 'was a boozy beggar', 'Who could think you under the table'
25+
new-philosopher 'David Hume' 'could out-consume Schopenhauer and Hegel'
26+
new-philosopher 'Wittgenstein' 'was a beery swine', 'Who was just as sloshed as Schlegel'
27+
new-philosopher 'John Stuart Mill' 'of his own free will', 'On half a pint of shandy was particularly ill'
28+
new-philosopher 'Nietzsche' 'There''s nothing Nietzsche couldn''t teach ya', 'Bout the raising of the wrist.'
29+
new-philosopher 'Plato' 'they say, could stick it away', 'Half a crate of whiskey every day'
30+
new-philosopher 'Aristotle' 'was a bugger for the bottle'
31+
new-philosopher 'Hobbes' 'was fond of his dram'
32+
new-philosopher 'Rene Descartes' 'was a drunken fart:', 'I drink, therefore I am'
33+
new-philosopher 'Socrates' 'is particularly missed','A lovely little thinker but a bugger when he''s pissed!'
34+
)
35+
36+
37+
1..100 | invoke-parallel -Throttle $ThrottleLimit -ProgressActivity "Parallel Philosofers" {
38+
39+
40+
41+
$pd = $philosopherData[($_ -1)% $philosopherData.Count]
42+
43+
1..100 | foreach {
44+
$op = switch($_ % 8)
45+
{
46+
0 { 'sleeping' }
47+
1 { 'drinking' }
48+
2 { 'drinking' }
49+
3 { 'thinking' }
50+
4 { 'drinking' }
51+
5 { 'drinking' }
52+
6 { 'eating' }
53+
7 { 'drinking' }
54+
}
55+
56+
$status = $pd.Treats[$_ % $pd.Treats.Length]
57+
58+
$name = $pd.Name
59+
$currentOperation = "$name is currently $op"
60+
Write-Progress -id $PSParallelProgressId -percent $_ -activity $pd.Name -Status $status -CurrentOperation $currentOperation
61+
Start-Sleep -milliseconds ($Milliseconds + 100 * (Get-Random -Minimum 3 -Maximum 7))
62+
}
63+
}

src/PSParallel/ImportArgumentCompleter.cs

-78
This file was deleted.

0 commit comments

Comments
 (0)