Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

singleton function added to handle segmentation fault by overlading the class object when runnung multiple times in loop #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions econt_sw/testing/utils/asic_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

import logging


""" function to handle loading config multiple times"""

def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class ASICSignals:
"""
Class for handling uhal ASIC signals
Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/fast_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

import logging

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class FastCommands:
"""Class to handle sending fast command signals over uhal"""

Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

import logging

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class IOBlock:
""" Class to handle IO blocks via uhal """

Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/link_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

import logging

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class LinkCapture:
"""Class to handle multiple link captures (lcs) over uhal. Always needs the link-capture name."""

Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/pll_lock_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
logger.setLevel(logging.INFO)
from time import sleep

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class PLLLockCount:
"""Class to monitor PLL_LOCK_B transition counters on FPGA"""

Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/stream_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

import logging

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class StreamCompare():
"""Class to handle stream compare via uhal"""
def __init__(self,logLevel="",logLevelLogger=10):
Expand Down
13 changes: 13 additions & 0 deletions econt_sw/testing/utils/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

import logging

""" Function to prevent initializing over and over """
def singleton(class_instance):
instances = {}

def get_instance(*args, **kwargs):
key = (class_instance, tuple(args), tuple(kwargs.items()))
if key not in instances:
instances[key] = class_instance(*args, **kwargs)
return instances[key]

return get_instance

@singleton
class TestVectors():
""" Class to handle test vectors """
def __init__(self,tv='testvectors',logLevel="",logLevelLogger=20):
Expand Down