Author kratsg
Recipients kratsg, ned.deily, ronaldoussoren
Date 2020-09-11.01:32:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Hi, this is my first issue, so I hope to try my best to explain the problem. Unfortunately, I cannot get an easy minimum-reproducible-example of this because I can only seem to invoke this behavior using pytest (6.0.1) on two tests of our code. First, let me explain the issue.

AttributeError: 'NoneType' object has no attribute '_alive'
Exception ignored in: <function WeakMethod.__new__.<locals>._cb at 0x1696c2a70>
Traceback (most recent call last):
  File "/Users/kratsg/.virtualenvs/pyhf-dev/lib/python3.7/", line 55, in _cb
    if self._alive:

occurs sometimes. Not always (feels like a race condition) and occurs after pytest has finished, which indicates it must be hitting garbage-collect. The backtrace isn't as helpful as it seems to jump from our code straight to the callback (indicating a garbage-collect):

-> pdf = pyhf.simplemodels.hepdata_like([50.0], [100.0], [10])
-> return Model(spec, batch_size=batch_size)
-> config=self.config, batch_size=self.batch_size
-> self.config.auxdata_order,
-> self._precompute()
-> self.allpar_viewer, self.selected_viewer, self.all_indices
-> index_selection = baseviewer.split(indices, selection=subviewer.names)
-> data = tensorlib.einsum('...j->j...', tensorlib.astensor(data))
-> return np.einsum(subscripts, *operands)
  <__array_function__ internals>(6)einsum()
> /Users/kratsg/.virtualenvs/pyhf-dev/lib/python3.7/
-> if self._alive:

Essentially, inside's _cb(), I tried to figure out what "self" was:

(Pdb) self
(Pdb) !arg
<weakref at 0x16f31c5d0; dead>

and it seems like the evaluation of "self._alive" is doomed to fail as self is None. So meth comes in, we take it apart into obj and func, define an inner function _cb that closes over a weakref to a weakref to obj and registers that function to fire when the underlying object gets gc'd. However, there seems to be an assumption that "self" is not None by the time the callback is fired.


Steps to reproduce:

Set up virtual env/install: python3 -m pip install -e .[complete]
Run pytest: pytest tests/ -vvvv -k "test_optimizer_stitching[scipy-numpy or test_optimizer_stitching[minuit-numpy" -s
Date User Action Args
2020-09-11 01:32:52kratsgsetrecipients: + kratsg, ronaldoussoren, ned.deily
2020-09-11 01:32:52kratsgsetmessageid: <>
2020-09-11 01:32:52kratsglinkissue41757 messages
2020-09-11 01:32:51kratsgcreate