Skip to content

Commit

Permalink
Added basic locking (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp authored Jan 14, 2024
1 parent 87c412b commit 4a4aaf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions partcad/src/partcad/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import copy
import random
import string
import threading

import build123d as b3d

Expand Down Expand Up @@ -38,6 +39,7 @@ def __init__(self, name=None, config={}):
else:
self.location = None
self.shape = None
self.lock = threading.RLock()

# self.children contains all child parts and assemblies
self.children = []
Expand All @@ -48,9 +50,10 @@ def __init__(self, name=None, config={}):
self.instantiated = False

def do_instantiate(self):
if not self.instantiated:
self.instantiate(self)
self.instantiated = True
with self.lock:
if not self.instantiated:
self.instantiate(self)
self.instantiated = True

def add(
self,
Expand Down
12 changes: 8 additions & 4 deletions partcad/src/partcad/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import math
import random
import string
from . import shape
import threading

import cadquery as cq
import build123d as b3d

from . import shape


class Part(shape.Shape):
def __init__(self, name=None, path=None, config={}, shape=None):
Expand All @@ -29,6 +31,7 @@ def __init__(self, name=None, path=None, config={}, shape=None):
self.config = config
self.path = path
self.shape = shape
self.lock = threading.RLock()

self.desc = None
if "desc" in config:
Expand All @@ -52,9 +55,10 @@ def set_shape(self, shape):
self.shape = shape

def get_shape(self):
if self.shape is None:
self.instantiate(self)
return self.shape
with self.lock:
if self.shape is None:
self.instantiate(self)
return self.shape

def ref_inc(self):
self.count += 1
Expand Down

0 comments on commit 4a4aaf6

Please sign in to comment.