Skip to content

Commit d73ba82

Browse files
committed
remove possibility to create multiple parallel sessions
1 parent 936b632 commit d73ba82

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/compas_session/lazyload.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
2-
import os
32
import pathlib
43
import shutil
4+
import sys
55
from typing import Any
66
from typing import Callable
77
from typing import Optional
@@ -41,7 +41,8 @@ class LazyLoadSession:
4141
4242
"""
4343

44-
_instances = {}
44+
# _instances = {}
45+
_instance = None
4546

4647
_name: str
4748
_timestamp: int
@@ -68,12 +69,23 @@ def __new__(
6869
depth: Optional[int] = None,
6970
delete_existing: bool = False,
7071
):
71-
basedir = pathlib.Path(basedir or os.getcwd())
72-
name = name or basedir.parts[-1]
72+
if cls._instance is None:
73+
if basedir:
74+
basedir = pathlib.Path(basedir)
75+
else:
76+
basedir = pathlib.Path(sys.argv[0]).resolve().parent
77+
78+
if not name:
79+
for filepath in basedir.iterdir():
80+
if filepath.is_dir():
81+
if filepath.suffix == ".session":
82+
name = filepath.stem
83+
break
84+
85+
if not name:
86+
name = basedir.parts[-1]
7387

74-
if name not in cls._instances:
7588
instance = object.__new__(cls)
76-
cls._instances[name] = instance
7789

7890
instance._name = name
7991
instance._timestamp = int(datetime.datetime.timestamp(datetime.datetime.now()))
@@ -91,7 +103,9 @@ def __new__(
91103

92104
instance.load_tolerance()
93105

94-
return cls._instances[name]
106+
cls._instance = instance
107+
108+
return cls._instance
95109

96110
def __init__(self, **kwargs) -> None:
97111
# this is accessed when the singleton is accessed in Rhino during consecutive command calls

0 commit comments

Comments
 (0)