[issue41757] weakmethod's ref is deleted before weakref's garbage-collect callback is executed

2020-09-14 Thread Giordon Stark


Giordon Stark  added the comment:

Hi Pablo,

Thanks for looking at this. Indeed, this seems to be fixed for me on python 3.8 
(I'm using docker image python:3.8-slim) and I'm unable to force the issue to 
come up.

I will go ahead and close this and link the corresponding PR 
(https://github.com/python/cpython/pull/16495) that fixed things up.

--
keywords: +patch
message_count: 4.0 -> 5.0
pull_requests: +21295
resolution:  -> fixed
stage:  -> patch review
status: open -> closed
pull_request: https://github.com/python/cpython/pull/16495

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



[issue41757] weakmethod's ref is deleted before weakref's garbage-collect callback is executed

2020-09-10 Thread Giordon Stark


Giordon Stark  added the comment:

This PR seems highly related: https://github.com/python/cpython/pull/18189. Not 
sure if it should be linked to this issue or not.

--

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



[issue41757] weakmethod's ref is deleted before weakref's garbage-collect callback is executed

2020-09-10 Thread Giordon Stark


New submission from Giordon Stark :

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: ._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


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 - -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 
<https://bugs.python.org/issue41757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com