I'm working on a highly detailed "random building generator". It's working so far, with a variable to pick the # of floors. 10 floors takes about 10 seconds 20 floors takes about 70 seconds 100 floors... after 5 minutes, I closed it out.
The thing I noticed is it's only using one thread. Each floor can be created with it's own thread without interfering with other threads. Within the loop that'll execute 100 times, how do I put "buildLayout" function call into threads, without breaking my PC?
Would this work? (Don't want to generate more threads than my PC can actually handle) import threading for floor in range (0, 100): thread = threading.Thread(target=buildLayout(self, context, offset, outsideWallObj, outsideDoorObj, outsideWindowObj)) threads.append(thread) thread.start()
for thread in threads: thread.join()
My biggest concern is I only want 1 thread running per core. Does python handle this automagically, or do I need to find the core count? If I need core count, how do I obtain it?
Current code listed below.
for floor in range (0, bpy.context.scene.user_vars.buildingHeight):
xPos = 0
yPos = 0
zPos = floor*4-1
offset = (xPos, yPos, zPos)
offset = Vector(offset)
buildLayout(self, context, offset, outsideWallObj, outsideDoorObj, outsideWindowObj)
import threading threads = [] for floor in range (0, vars.buildingHeight): thread = threading.Thread(target=buildLayout(varsY)) threads.append(thread) thread.start()
– Mike Dec 14 '19 at 10:35