Using the Grasshopper python component I wrote a code that intersects lots of breps with each other.
To make it faster I used parallel processing wich worked fine under Rhino 5 32bit, on a 64bit Rhino the component crashes my whole Rhino instantly.
The function used was Rhino.Geometry.Intersect.Intersection.BrepBrep()
many of the Rhino Common methods are not threadsave and will crash rhino but in your case it may depend on the implementation of the treading module used or the way you append results of the intersection. Without a code example it is hard to track down errors in your code.
Below example using System.Threading and Rhino.Geometry.Intersect.Intersection.BrepBrep() seems to work without crashing Rhino x64:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import System
import System.Threading.Tasks as tasks
import itertools
def DoSomething():
ids = rs.GetObjects("Select breps", 8+16, True, False)
if not ids: return
breps = [rs.coercebrep(id, True) for id in ids]
pairs = list(itertools.combinations(breps, 2))
curves = [None] * len(pairs)
tolerance = scriptcontext.doc.ModelAbsoluteTolerance
intersector = Rhino.Geometry.Intersect.Intersection
def MyWorker(w):
rc, c, p = intersector.BrepBrep(pairs[w][0], pairs[w][1], tolerance)
if rc: curves[w] = c
tasks.Parallel.ForEach(xrange(len(pairs)), MyWorker)
flatten = list(itertools.chain(*curves))
crv_ids = [scriptcontext.doc.Objects.AddCurve(c) for c in flatten]
DoSomething()
Thanks a lot for your detailed answer. As I am fairly new to coding in general there are some things going on in your code I am not familiar with. I used the ghpythonlib.parallel.run() wich also did all the appending for me.
I will look into your code and see if I can make use of system.threading instead.
By the way… I got an error message when I accidently ran the old code again.
Something like Runtime Error: Vital function call. Unfortunately the expected crash happened a second later so I couldnt take a screenshot.
Here is the .gh file. “Works” (Works not =D ) with an empty rhino scene. The results don’t vary with changed geometry.
Rhino crashes as soon as I connect the parallel version of the python component but as mentioned it didn’t under 32Bit so I am pretty confused about what the problem is.
my script posted above is not a grasshopper / python ready code but usable from within rhino to show that Rhino.Geometry.Intersect.Intersection.BrepBrep() is threadsave. Please try this:
close GH
open the example geometry posted above
open the Python script editor using _EditPythonScript
paste my script example from above in the code area of the Python editor
run the script, when it asks for the breps, select all spheres, then _Enter
Do you get a crash ?
I´ve opened your gh file but it does not contain the code posted above in the python component. To get this work in a GH python component, do this:
double click the canvas in GH and add new empty Python script component.
right click on the x input and set it to List Access
Just go through it line by line. Comment out everything first, then start from the top to see where the crash occurs. I cannot say anything about ghpythonlib.parallel as i never used it.
Already tried that but with no success as long as I have nu clue on why this works in 32Bit but not in 64 I am pretty much helpless. You dont happen to know whom I could ask about that matter do you?
I tested your definition in both Rhino 5SR12 from August of last year and in Rhino WIP and there was no crash even after connecting the second scripting component (I assume the crash was in there?). Is there something else I need to do to reproduce?
Hi @piac,
first I want to thank you for taking the time to help me.
I just tested again and keep getting the same problem. Instant crash after connecting the second script.
I am running win 7, with Rhino Version 5 SR12 64-bit (5.12.50810.13095, 10.08.2015).
You probably havn’t got any leads on what else might cause this? Would a crash dump file help to solve this problem?