Skip to content

Commit

Permalink
python: Solved Python bindings Context destructor bug.
Browse files Browse the repository at this point in the history
The Device class was only holding a weakref of the Context object. This could lead to calling the Context's destructor before removing all its references.
An example of crash can be found in the following issue: #628.
Weakref was permitting Python to call the Context destructor even if it was referenced in the device object. Changing the weakref to a full reference should solve the issue.

Signed-off-by: Cristi Iacob <[email protected]>
  • Loading branch information
cristi-iacob authored and dNechita committed Dec 17, 2020
1 parent 88b23f5 commit fe86c6b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions bindings/python/iio.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from enum import Enum
from os import strerror as _strerror
from platform import system as _system
import weakref
import abc

if "Windows" in _system():
Expand Down Expand Up @@ -1301,7 +1300,7 @@ def __init__(self, ctx, _device):
An new instance of this class
"""
super(Device, self).__init__(_device)
self.ctx = weakref.ref(ctx)
self.ctx = ctx

def _set_trigger(self, trigger):
_d_set_trigger(self._device, trigger._device if trigger else None)
Expand Down

0 comments on commit fe86c6b

Please sign in to comment.