New submission from Giordon Stark <kratsg+pyt...@gmail.com>:

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/weakref.py", 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):

/Users/kratsg/pyhf/tests/test_validation.py(1082)test_optimizer_stitching()
-> pdf = pyhf.simplemodels.hepdata_like([50.0], [100.0], [10])
  /Users/kratsg/pyhf/src/pyhf/simplemodels.py(64)hepdata_like()
-> return Model(spec, batch_size=batch_size)
  /Users/kratsg/pyhf/src/pyhf/pdf.py(590)__init__()
-> config=self.config, batch_size=self.batch_size
  /Users/kratsg/pyhf/src/pyhf/pdf.py(339)__init__()
-> self.config.auxdata_order,
  /Users/kratsg/pyhf/src/pyhf/parameters/paramview.py(66)__init__()
-> self._precompute()
  /Users/kratsg/pyhf/src/pyhf/parameters/paramview.py(78)_precompute()
-> self.allpar_viewer, self.selected_viewer, self.all_indices
  /Users/kratsg/pyhf/src/pyhf/parameters/paramview.py(27)extract_index_access()
-> index_selection = baseviewer.split(indices, selection=subviewer.names)
  /Users/kratsg/pyhf/src/pyhf/tensor/common.py(59)split()
-> data = tensorlib.einsum('...j->j...', tensorlib.astensor(data))
  /Users/kratsg/pyhf/src/pyhf/tensor/numpy_backend.py(268)einsum()
-> return np.einsum(subscripts, *operands)
  <__array_function__ internals>(6)einsum()
> /Users/kratsg/.virtualenvs/pyhf-dev/lib/python3.7/weakref.py(56)_cb()
-> if self._alive:

Essentially, inside weakref.py'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:

Clone: https://github.com/scikit-hep/pyhf
Set up virtual env/install: python3 -m pip install -e .[complete]
Run pytest: pytest tests/test_validation.py -vvvv -k 
"test_optimizer_stitching[scipy-numpy or test_optimizer_stitching[minuit-numpy" 
-s

----------
components: macOS
messages: 376699
nosy: kratsg, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: weakmethod's ref is deleted before weakref's garbage-collect callback is 
executed
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41757>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to