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

👌 IMPROVE: Terminal states do not reference process #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Feb 10, 2021

This removes any cyclic references in finished processes,
allowing for garbage collection to be be automatically triggered in CPython.

closes #198 and should be a partial fix for aiidateam/aiida-core#4603

Note, without this change, garbage collection of the process on termination is possible (i.e. CPython can handle circular references).
However, it means that it is not automatically triggered, and thus the garbage collection has to be called/triggered in some other way.
This has been shown to be an issue with the AiiDA daemons, which keep the process in memory (and can lead to large amounts of memory being held).
I can't think of any good way to trigger such a garbage collection on process termination, since the process can't call garbage collection on itself?

I am going to create an alpha release from this branch (https://pypi.org/project/plumpy/0.18.5a0/), in order to test that this does not lead to any issues in the aiida-core tests

This removes any cyclic references in finished processes,
allowing for garbage collection to be be automatically triggered in CPython.
@codecov-io
Copy link

codecov-io commented Feb 10, 2021

Codecov Report

Merging #205 (9d2ee16) into develop (bf94508) will decrease coverage by 0.06%.
The diff coverage is 83.34%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #205      +/-   ##
===========================================
- Coverage    90.66%   90.60%   -0.05%     
===========================================
  Files           22       22              
  Lines         2952     2956       +4     
===========================================
+ Hits          2676     2678       +2     
- Misses         276      278       +2     
Impacted Files Coverage Δ
plumpy/base/state_machine.py 86.24% <75.00%> (-0.29%) ⬇️
plumpy/process_states.py 88.67% <85.72%> (-0.31%) ⬇️
plumpy/version.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf94508...9d2ee16. Read the comment docs.

@chrisjsewell
Copy link
Member Author

pinging @muhrin, if you have time to have a look at some point cheers

@chrisjsewell
Copy link
Member Author

testing against aiida-core: aiidateam/aiida-core#4743

):
"""
:param process: The associated process
:param exception: The exception instance
:param trace_back: An optional exception traceback
"""
super().__init__(process)
super().__init__(None) # terminal state does not require process ref
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just elaborate on this comment a litle to say
'Terminal states don't get a backreference to the state machine so that it's easier for python to clear the memory'
or something to that effect just so that it's clear:

  1. Why this was done, and,
  2. So it's clear under which circumstances it's None (which you've already stated actually)

"""
:param state_machine: The process this state belongs to
"""
self.state_machine = state_machine
self.state_machine: Optional[StateMachine] = state_machine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a ValueError might be useful to be riased if state_machine is None for non terminal states. What do you think?

If it mattered more I would almost change the class hierarchy to have a TerminalState which doesn't even take it as an argument and is hardcoded to return False on is_terminal but I don't think it's worth it in this case but the exception might be useful. Just because I don't know how hardcoded the assumption is that the state_machine returns a non-None.

@chrisjsewell
Copy link
Member Author

chrisjsewell commented Feb 11, 2021

Hmm, from https://github.com/aiidateam/aiida-core/runs/1878917673?check_suite_focus=true, I think this might be causing something to hang in tests/engine/test_utils.py

@chrisjsewell
Copy link
Member Author

Hmm, from aiidateam/aiida-core/runs/1878917673?check_suite_focus=true, I think this might be causing something to hang in tests/engine/test_utils.py

This was actually because of: aiidateam/aiida-core#4751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set self.state_machine to None for terminal states
3 participants