Hello,
I have an AiiDAlab interface with several QE workchains running. I need to check regularly if they are all finished to advance to the next step automatically. To do that I use threading
with my target function as follows
def _check_workchain_finished(self, workchains):
checking_interval = 3
while True:
time.sleep(checking_interval)
done = True
for workchain in workchains:
if not workchain.is_finished:
done = False
if done:
self.state = self.State.SUCCESS
self.validation_nodes = workchains
break
where workchain
is the list of runnings QE workchains that I have submitted.
I create a thread as
thread = threading.Thread(target=self._check_workchain_finished,
args=[nodes])
thread.start()
But there is exception raised at if not workchain.is_finished
Exception in thread Thread-12 (_check_workchain_finished):
Traceback (most recent call last):
File "/usr/lib64/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/hungdt/works/IMMAD/codes/IMMAD/substitution.py", line 326, in _check_workchain_finished
if not workchain.is_finished:
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/orm/nodes/process/process.py", line 375, in is_finished
return self.process_state == ProcessState.FINISHED
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/orm/nodes/process/process.py", line 279, in process_state
state = self.base.attributes.get(self.PROCESS_STATE_KEY, None)
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/orm/nodes/attributes.py", line 77, in get
attribute = self._backend_node.get_attribute(key)
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/storage/psql_dos/orm/nodes.py", line 241, in get_attribute
return self.model.attributes[key]
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/storage/psql_dos/orm/utils.py", line 85, in __getattr__
self._ensure_model_uptodate(fields=(item,))
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/aiida/storage/psql_dos/orm/utils.py", line 162, in _ensure_model_uptodate
self.session.expire(self._model, attribute_names=fields)
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/sqlalchemy/orm/session.py", line 2431, in expire
self._expire_state(state, attribute_names)
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/sqlalchemy/orm/session.py", line 2434, in _expire_state
self._validate_persistent(state)
File "/home/hungdt/venv/aiida/lib64/python3.10/site-packages/sqlalchemy/orm/session.py", line 3161, in _validate_persistent
raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Instance '<DbNode at 0x7f106e7804c0>' is not persistent within this Session
Do you know what is the problem here and how to solve it? Thank you.