Skip to content
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
24 changes: 23 additions & 1 deletion .github/workflows/pytest-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ jobs:
senzingsdk-version: [production-v4, staging-v4]

steps:
- name: Test enabling cores
run: |
ulimit -c
ulimit -c unlimited
ulimit -c

- name: Test access to core dump directory
run: |
sudo touch /cores/test
ls /cores
sudo rm /cores/test

- name: Checkout repository
uses: actions/checkout@v5
with:
Expand Down Expand Up @@ -80,7 +92,17 @@ jobs:
- name: Run pytest
run: |
source ./venv/bin/activate
pytest tests/ --verbose --capture=no --cov=src
sudo ulimit -c unlimited
echo "sudo ulimit -c"
sudo ulimit -c
echo "sudo env:"
sudo -E bash -c 'env'
sudo -E bash -c 'export PYTHONPATH="/Users/runner/work/sz-sdk-python-core/sz-sdk-python-core/src"; export LD_LIBRARY_PATH="/Users/runner/senzing/er/lib:/Users/runner/senzing/er/lib/macos"; export DYLD_LIBRARY_PATH="/Users/runner/senzing/er/lib:/Users/runner/senzing/er/lib/macos"; ulimit -c unlimited; ulimit -c; pytest tests/ --verbose --capture=no --cov=src; env'
sudo chmod -R +rwx /cores/*
- uses: actions/upload-artifact@v4
with:
name: crashes
path: /cores

- name: Rename coverage file
env:
Expand Down
87 changes: 74 additions & 13 deletions src/senzing_core/szabstractfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ class SzAbstractFactoryCore(SzAbstractFactory):
_engine_instances = weakref.WeakValueDictionary() # type: ignore[var-annotated]
_factory_instances = weakref.WeakValueDictionary() # type: ignore[var-annotated]

# TODO -
# def __new__(
# cls,
# instance_name: str = "",
# settings: Union[str, Dict[Any, Any]] = "",
# config_id: int = 0,
# verbose_logging: int = 0,
# ) -> SzAbstractFactoryCore:

# with cls._constructor_lock:
# args_hash = cls._create_args_hash(instance_name, settings, config_id, verbose_logging)
# instance = super().__new__(cls)
# instance._args_hash = args_hash # type: ignore[attr-defined]

# if cls not in cls._factory_instances.keys():
# cls._factory_instances[cls] = instance
# else:
# if args_hash == cls._factory_instances[cls]._args_hash:
# instance = cls._factory_instances[cls]

# if args_hash != cls._factory_instances[cls]._args_hash:
# raise SzSdkError(
# "an abstract factory instance exists with different arguments, to use new arguments destroy the active instance first (NOTE: This will destroy Senzing objects created by the active instance!)"
# )

# return instance
def __new__(
cls,
instance_name: str = "",
Expand All @@ -105,22 +131,40 @@ def __new__(
) -> SzAbstractFactoryCore:

with cls._constructor_lock:
# TODO -
print("\nIn factory __new__...", flush=True)
print(f"\t{instance_name}", flush=True)
print(f"\t{settings}", flush=True)
print(f"\t{config_id}", flush=True)
print(f"\t{verbose_logging}", flush=True)
args_hash = cls._create_args_hash(instance_name, settings, config_id, verbose_logging)
instance = super().__new__(cls)
instance._args_hash = args_hash # type: ignore[attr-defined]
# instance = super().__new__(cls)
# instance._args_hash = args_hash # type: ignore[attr-defined]

if cls not in cls._factory_instances.keys():
cls._factory_instances[cls] = instance
else:
if args_hash == cls._factory_instances[cls]._args_hash:
instance = cls._factory_instances[cls]

if args_hash != cls._factory_instances[cls]._args_hash:
raise SzSdkError(
"an abstract factory instance exists with different arguments, to use new arguments destroy the active instance first (NOTE: This will destroy Senzing objects created by the active instance!)"
)

return instance
# TODO -
print("\tCreating new factory", flush=True)
# cls._factory_instances[cls] = instance
new_instance = super().__new__(cls)
new_instance._args_hash = args_hash # type: ignore[attr-defined]
cls._factory_instances[cls] = new_instance
return new_instance

# else:
if args_hash == cls._factory_instances[cls]._args_hash:
# TODO -
print("\tReturning current factory", flush=True)
current_instance: SzAbstractFactoryCore = cls._factory_instances[cls]
# return cls._factory_instances[cls]
return current_instance
# else:
# if args_hash != cls._factory_instances[cls]._args_hash:

# TODO -
print("\tRaising SzSdkError", flush=True)
raise SzSdkError(
"an abstract factory instance exists with different arguments, to use new arguments destroy the active instance first (NOTE: This will destroy Senzing objects created by the active instance!)"
)

def __init__(
self,
Expand Down Expand Up @@ -225,41 +269,58 @@ def create_product(self) -> SzProduct:
@_check_is_destroyed
@_method_lock
def destroy(self) -> None:
# TODO -
print("\nIn destroy() calling finalizer", flush=True)
self._finalizer()

@staticmethod
def _do_destroy() -> None:
# TODO -
print("\nIn _do_destroy()", flush=True)

with suppress(KeyError, SzSdkError):
for engine_object in SzAbstractFactoryCore._engine_instances.values():
# TODO -
print(f"\tDestroying engine instance in _engine_instances: {engine_object}", flush=True)
engine_object._destroy() # pylint: disable=protected-access
engine_object._is_destroyed = True # pylint: disable=protected-access

SzAbstractFactoryCore._engine_instances.clear()

# TODO -
print("\nStarting to destroy real engine objects...", flush=True)
sz_destroy_configmanager = SzConfigManagerCore()
while True:
try:
# TODO -
print("\tSzConfigManagerCore", flush=True)
sz_destroy_configmanager._internal_only_destroy() # pylint: disable=protected-access
except SzNotInitializedError:
break

sz_destroy_diagnostic = SzDiagnosticCore()
while True:
try:
# TODO -
print("\tSzDiagnosticCore", flush=True)
sz_destroy_diagnostic._internal_only_destroy() # pylint: disable=protected-access
except SzNotInitializedError:
break

sz_destroy_engine = SzEngineCore()
while True:
try:
# TODO -
print("\tSzEngineCore", flush=True)
sz_destroy_engine._internal_only_destroy() # pylint: disable=protected-access
except SzNotInitializedError:
break

sz_destroy_product = SzProductCore()
while True:
try:
# TODO -
print("\tSzProductCore", flush=True)
sz_destroy_product._internal_only_destroy() # pylint: disable=protected-access
except SzNotInitializedError:
break
Expand Down
10 changes: 10 additions & 0 deletions src/senzing_core/szconfigmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ def _initialize(
self.instance_name = instance_name
self.settings = as_str(settings)
self.verbose_logging = verbose_logging
# TODO -
print("\nSzConfigManager -> _initialize...", flush=True)
print(f"{self.instance_name = }", flush=True)
print(f"{self.settings = }", flush=True)
print(f"{self.verbose_logging = }", flush=True)
instance_name_c_char_p = as_c_char_p(instance_name)
settings_c_char_p = as_c_char_p(as_str(settings))
print(f"{instance_name_c_char_p = }", flush=True)
print(f"{settings_c_char_p = }", flush=True)

result = self._library_handle.SzConfigMgr_init(
as_c_char_p(instance_name),
as_c_char_p(as_str(settings)),
Expand Down
File renamed without changes.
Loading
Loading