Thank you for the suggestion Tim!

I tried something similar. I cannot call methods if I create an instance of the 
UtilsClass class, as I always get an error message:

Could not convert argument 0 for call to UtilsClassMethod
but I can if I call them as static methods. So I tried this:

utils1 = MapWinGIS.Utils()
utils2 = MapWinGIS.Utils()

returnedValue1 = MapWinGIS.UtilsClass.UtilsClassMethod(utils1, variable1a, 
variable1b)returnedValue2 = MapWinGIS.UtilsClass.UtilsClassMethod(utils2, 
variable2a, variable2b)
But this did not fix the problem. returnedValue1 still returns True, while 
returnedValue2 returns False.



--------------------------------
    On Saturday, November 26, 2016 7:10 AM, Tim Baigent <t...@clear.net.nz> 
wrote:
 
 I'm out of my depth here, forgive me for not keeping quiet!
But perhaps you are be best to create separate instances of the MapWinGIS.Utils 
class, one for each call, so that there is no chance for inadverently sharing 
values between instance members.
So something like this (and here I'm *really* out of my depth):
utils1 = MapWinGIS.Utils()utils2 = MapWinGIS.Utils()...returnedValue1 = 
utils1(variable1a, variable1b)returnedValue2 = utils2(variable2a, variable2b)
Is that possible?
On 26/11/2016, at 7:47 AM, Djordje Spasic via Ironpython-users 
<ironpython-users@python.org> wrote:


Hi Steve,

I imagine that you do not have any spare time left.
Still, do you have any suggestion on how I can solve this issue?

Thank you for the reply.

Kind regards,
Djordje Spasic 

    On Monday, November 7, 2016 11:55 PM, Djordje Spasic via Ironpython-users 
<ironpython-users@python.org> wrote:
 

 Hello,

I have an issue. I am using ironpython 2.7 editor called through Rhino 5 
application, and I load a single .dll file from an application called 
MapWinGIS. Like so:
dll_filePath = 
"C:\ProgramFiles\MapWinGIS\Interop.MapWinGIS.dll"clr.AddReferenceToFileAndPath(dll_filePath)import
 MapWinGIS
The problem is that I can only call a particular method once.
If try to do that the second time, the same method returns "False". When method 
works correctly (the first time) it return: "True".

The problem goes away if I restart the Rhino 5 application (and ironpython 2.7 
editor along with it).


Why is this happening? I contacted the developers of upper mentioned MapWinGIS 
application, and they said that they can not replicate this behavior and that I 
should ask this question on ironpython mailing list. They suggested that I need 
to somehow "free the memory before you do the second run of the method".

So to make my problem more clear, this is what happens:

If run a script containing the this particular method twice, the first call of 
the method returns "True", the second one "False":

variable1a = "something1a"variable1b = "something1b"returnedValue1 
=MapWinGIS.someClass.someMethod1(variable1a, variable1b)  # returns "True" 
variable2a = "something2a"variable2b = "something2b"returnedValue2 = 
MapWinGIS.someClass.someMethod1(variable2a,variable2b)  #returns "False"
If run the same script again, both upper calls of 
MapWinGIS.someClass.someMethod1 method return "False".
If I restart my Rhino 5 application, then again the same thing happens: "True" 
is returned on first MapWinGIS.someClass.someMethod1 call, while "False" is 
returned on the second call. If run the script again, then they both return 
"False". For every other run of the script, I get "False" on both calls. And 
this continues until I restart Rhino 5.

I perfectly understand that it is impossible for anyone from Ironpython mailing 
list to know the exact cause of this problem.

But can you at least help me with "free the memory before you do the second run 
of the method" part?

I tried deleting all the variables after the first call, calling the garbage 
collector and also removing the .dll file from the list of loaded assemblies. 
Like this:
import clrimport gc dll_filePath = 
"C:\ProgramFiles\MapWinGIS\Interop.MapWinGIS.dll"clr.AddReferenceToFileAndPath(dll_filePath)import
 MapWinGIS variable1a = "something1a"variable1b = "something1b"returnedValue1 
=MapWinGIS.someClass.someMethod1(variable1a, variable1b)  # returns "True" # 
delete all variablesdel dll_filePath; del variable1a; del variable1b; del 
returnedValue1; del MapWinGIS # remove the .dll from the listof assembliesfor 
i,assembly in enumerate(clr.References):    if assembly.GetName().Name == 
"Interop.MapWinGIS":        clr.References.RemoveAt(i)        break # collect 
garbagegc.collect()   dll_filePath2 = 
"C:\ProgramFiles\MapWinGIS\Interop.MapWinGIS.dll"clr.AddReferenceToFileAndPath(dll_filePath2)import
 MapWinGIS variable2a = "something2a"variable2b = "something2b"returnedValue2 = 
MapWinGIS.someClass.someMethod1(variable2a,variable2b)  #returns "False"

But it is not working (I still get the "True" on first method call, and "False" 
on second).
I also tried to exchange the variable1a and variable1b with variable2a and 
variable2b. Or even use the same variables in both 
MapWinGIS.someClass.someMethod1 calls. Still, no improvement.
The MapWinGIS.someClass.someMethod1 that I am calling is actually: 
MapWinGIS.UtilsClass.OGR2OGR.
I named it MapWinGIS.someClass.someMethod1 to make it easier for others to 
follow the code. Not sure if this was good idea. If it wasn't I apologize.


This issue is driving me crazy. I would be very grateful for any kind of advice.
Thank you in advance!


Kind regards,
Djordje Spasic


_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users


   

_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users



   
_______________________________________________
Ironpython-users mailing list
Ironpython-users@python.org
https://mail.python.org/mailman/listinfo/ironpython-users

Reply via email to