-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
Segfaults when creating Solution from scratch #1762
Comments
I wonder if we're not keeping a reference to the reaction objects so they get garbage collected, where the explicit list comprehension creates that reference so things work? |
Could be. An easy fix would be to move the list comprehension into the |
@bryanwweber ... on second thought, I believe that it may be the Python lambda function
that gets garbage collected. C++ will have all pointers in place, but the callback is gone. |
I think it's the import cantera as ct
from math import exp
gas0 = ct.Solution('gri30.yaml')
species = gas0.species()
reactions = gas0.reactions()
custom_reactions = gas0.reactions()
L = lambda T: 38.7 * T**2.7 * exp(-3150.15/T)
rate1 = ct.CustomRate(L)
custom_reactions[2] = ct.Reaction(
equation='H2 + O <=> H + OH',
rate=rate1)
gas1 = ct.Solution(thermo='ideal-gas', kinetics='gas',
species=species, reactions=custom_reactions)
# Removing either of these 'del' statements avoids segfault
del custom_reactions
del rate1
gas1.net_production_rates # segfaults Interestingly, I also find that there's no segfault if the rate is a different type, for example |
@speth ... thanks for shedding more light on this issue. The Python I haven't investigated whether this also affects |
Oh, well, here's the answer. We do explicitly hold onto these objects in cantera/interfaces/cython/cantera/kinetics.pyx Lines 197 to 202 in 9d0e54a
It's just the pathway of constructing a Solution object from a list of reactions calls the C++ method directly instead of using add_reaction (in _SolutionBase._init_parts ):cantera/interfaces/cython/cantera/solutionbase.pyx Lines 219 to 230 in 9d0e54a
And yes, this affects ExtensibleRate as well as CustomRate .
|
Problem description
When two
Solution
objects shareReaction
objects, there is a risk of segfaults.Steps to reproduce
Run the following script:
Behavior
The variants
are safe, whereas
cause segfaults (or bus errors resulting in crashes).
System information
main
Other remarks
custom_reactions.py
sample.gas2
object corruptsgas1
?The text was updated successfully, but these errors were encountered: