Folks, I'm stuck on what must be a bleeding obvious mistake that I can't see
.
This is NOT Iron Python for .NET - it's plain PSF python 2.7.2 for Windows,
running in a CMD window process started from my .NET code.
My code runs a python script with an argument, via a Windows process. The
argument is formed within the .NET code, and a single process will run
correctly and terminate normally with the correct result.
The same argument "sets" can be manually pasted into a command line (CMD
window / DOS box) to run successfully every time, for every test argument
"set" that I have.
However, if I start consecutive processes in a loop from my .NET code (which
run the same python script, but with different arguments), I find that not
all of the processes run - I can see that (say) 6 processes actually start,
but the some of then close after others begin. The remaining process will
run properly and give the correct results.
This is confusing, in that with 6 processes started, 4 continue (and they
are not consecutive - I identify them numerically, and see numbers 36 and 39
missing out of 35 to 40 started); with 2 started, 1 continues - and it can
be either the first or the second one. I'm sure further testing would show
more variation.
I can repeat the scenario with different inputs - it is the multiple
invocations of a windows process that seem to cause the problem.
This is a simplified version of my code - it could be an array of
parameters/arguments, rather than those held in the checked items in a
Windows Forms ListView.
' Process only the selected (checked) cases
Private Sub Button4_Click(sender As System.Object, e As
System.EventArgs) Handles Button4.Click
If ListView1.CheckedItems.Count = 0 Then Exit Sub
Dim item As ListViewItem
Dim checkedItems As ListView.CheckedListViewItemCollection =
ListView1.CheckedItems
For Each item In checkedItems
Dim args As String = item.SubItems(0).Text
StartProcess(args)
Next
End Sub
' Start a process using python and the py script
Sub StartProcess(ByVal MyArgs As String)
Dim p As New Process
p.StartInfo.FileName = "C:\Python27\python.exe"
p.StartInfo.Arguments = MyArgs
p.Start()
End Sub
The python command line ends up something like this -
C:\python27\python.exe MyPythonScript.py args
While MyPythonScript.py imports a function from another script in the same
folder, I can open multiple separate command windows (manually, through
Windows Explorer) in the same folder location, and run several jobs in that
fashion each with a different args string - ie, it is not a sharing
violation that I am encountering.
_____
Ian Thomas
Victoria Park, Western Australia