Skip to content

Ensure multithreading works#126

Merged
ZedThree merged 4 commits into
masterfrom
python-314
Jun 18, 2025
Merged

Ensure multithreading works#126
ZedThree merged 4 commits into
masterfrom
python-314

Conversation

@dschwoerer
Copy link
Copy Markdown
Contributor

Needed for python 3.14

Fixes #123

Needed for python 3.14
Comment thread src/boutdata/data.py Outdated
Comment on lines +1632 to +1638
def _clean_for_mp(self):
new = object.__new__(BoutOutputs)
new.__dict__ = self.__dict__.copy()
new._file0 = None
new._root_file = None
new._workers = None
return new
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does __getstate__ allow us to do this without having to call _clean_for_mp()? Then it might just be:

Suggested change
def _clean_for_mp(self):
new = object.__new__(BoutOutputs)
new.__dict__ = self.__dict__.copy()
new._file0 = None
new._root_file = None
new._workers = None
return new
def __getstate__(self):
new = self.__dict__.copy()
new.pop("_file0")
new.pop("_root_file")
new.pip("_workers")
return new

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The question is, do users expect to be able to pickle an object and still have _file0, _root_file and _workers?
How does BoutOptions behave if that is not set?

It is probably fine to allow BoutOptions to be pickled, and if someone in the future wants to unpickle it, and it is broken for their use case, we can add the fixes to __setstate__ ...

I will update the PR, thanks for the hints 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure, but I agree we can cross that bridge when we come to it :)

dschwoerer and others added 3 commits June 18, 2025 11:30
This is needed so that multithreading works with python 3.14.
@ZedThree ZedThree merged commit 73f3039 into master Jun 18, 2025
@ZedThree ZedThree deleted the python-314 branch June 18, 2025 09:46
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.

test failure with python 3.14: NotImplementedError: Dataset is not picklable

2 participants