You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cothread locks up in response to runtime warning from numpy #78
Ths generates the following output (I have elided the full paths for clarity):
Hello
.../site-packages/numpy/core/_methods.py:263: RuntimeWarning: Degrees of freedom <= 0 for slice
keepdims=keepdims, where=where)
^\Quit (core dumped)
One interesting detail of note: only one of three warnings is generated in this case, if numpy.std([]) is computed outside of a cothread the following is printed:
.../site-packages/numpy/core/_methods.py:263: RuntimeWarning: Degrees of freedom <= 0 for slice
keepdims=keepdims, where=where)
.../site-packages/numpy/core/_methods.py:223: RuntimeWarning: invalid value encountered in true_divide
arrmean, rcount, out=arrmean, casting='unsafe', subok=False)
.../site-packages/numpy/core/_methods.py:254: RuntimeWarning: invalid value encountered in double_scalars
ret = ret.dtype.type(ret / rcount)
nan
This is tested for Python 3.7.2 and cothread version 2.19.1.
There appears to be something wrong with how Cothread handles Numpy's error handling. Whatever interaction is happening is causing this permanent hang. It also seems to somehow be overriding the Numpy error handling setting.
The below program demonstrates the call inside of numpy.std() that is where the hang is actually happening. Note that we are doing numpy.seterr(all='raise'), which should make all Warnings instead convert into Exceptions. They are not, we just get a hang instead.
import numpy
import cothread
from numpy._core import umath as um
def ticker():
print('Hello')
numpy.seterr(all='raise')
arrmean = numpy.zeros(1)
um.true_divide(arrmean, 0, out=arrmean,
casting='unsafe', subok=False)
print('End')
cothread.Spawn(ticker)
cothread.Yield()
print('Bye')
Compare this to the same program running outside of a Cothread:
import numpy
import cothread
from numpy._core import umath as um
numpy.seterr(all='raise')
arrmean = numpy.zeros(1)
arrmean = um.true_divide(arrmean, 0, out=arrmean,
casting='unsafe', subok=False)
print(arrmean)
Which yields the expected Exception from Numpy:
Traceback (most recent call last):
File "/scratch/eyh46967/dev/cothread/test.py", line 20, in <module>
arrmean = um.true_divide(arrmean, 0, out=arrmean,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FloatingPointError: invalid value encountered in divide
This seems to be a regression from Python2: I can repeat this test with dls-python and the exception is reported normally. (In my test I'm simply using numpy.std([]) as this is a little less brittle than trying to import from numpy._core, which seems to be quite version specific.)
Activity
AlexanderWells-diamond commentedon Oct 8, 2025
There appears to be something wrong with how Cothread handles Numpy's error handling. Whatever interaction is happening is causing this permanent hang. It also seems to somehow be overriding the Numpy error handling setting.
The below program demonstrates the call inside of
numpy.std()that is where the hang is actually happening. Note that we are doingnumpy.seterr(all='raise'), which should make all Warnings instead convert into Exceptions. They are not, we just get a hang instead.Compare this to the same program running outside of a Cothread:
Which yields the expected Exception from Numpy:
Araneidae commentedon Oct 9, 2025
This seems to be a regression from Python2: I can repeat this test with
dls-pythonand the exception is reported normally. (In my test I'm simply usingnumpy.std([])as this is a little less brittle than trying to import fromnumpy._core, which seems to be quite version specific.)