Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions backend/staticfiles/synthesis/lib/inputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from multiprocessing import shared_memory, Condition
from multiprocessing import shared_memory

import numpy as np
from lib.exceptions import InvalidInputNameException
Expand All @@ -13,12 +13,11 @@ def create_readonly_wire(name):
return shm

def create_number_wire(name, size):
try:
shm = shared_memory.SharedMemory(name=name)
except:
shm = shared_memory.SharedMemory(name=name, create=True, size=size)
# self.shms.append(shm)
return shm
try:
shm = shared_memory.SharedMemory(name=name)
except FileNotFoundError:
shm = shared_memory.SharedMemory(name=name, create=True, size=size)
return shm

class Inputs:

Expand All @@ -28,11 +27,6 @@ def __init__(self, input_data) -> None:
self.inputs = input_data
self._enable_data = self.inputs[Inputs.ENABLE_NAME] if Inputs.ENABLE_NAME in self.inputs else None

def _init_enabled(self) -> None:
# This function is redundant for now, its not being used anywhere
self._enable_data = self.inputs[Inputs.ENABLE_NAME] if Inputs.ENABLE_NAME in self.inputs else None
self._enable_condition = Condition(self.inputs[Inputs.ENABLE_NAME]["lock"]) if self.enable_wire else None

def read(self, name):
if self.inputs.get(name) is None:
raise InvalidInputNameException(f"{name} is not declared in inputs")
Expand Down Expand Up @@ -196,12 +190,10 @@ def enabled(self, _enabled: bool):


else:
# Wire doesn't exist yet, ideally has to be created and set
# TODO: Is this case necessary?
# Yep case is definitely necessary especially by this implementation

# Wire doesn't exist yet: this implementation requires it to be
# created and set here.
if _enabled:
# If the command has been give to enable the wire
# The command has been given to enable the wire
wire_name = self._enable_data["wire"]
# Value of the wire to be set
wire_val = np.array([1])
Expand Down