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
I have an error where I encounter segfaults sometimes when using `astropy.table.Table.read(file, format='ascii'). Since the segfault automatically exits the python interpreter, I don't have a traceback to provide. However, the error seems to occur more frequently when I call the reader multiple times, on somewhat large (~thousands of lines) ascii files.
At the interpreter, I get this:
/Users/tsrice/anaconda/bin/python.app: line 3: 37109 Segmentation fault: 11 /Users/tsrice/anaconda/python.app/Contents/MacOS/python "$@"
Please let me know if I can provide more information - again, I'm not used to reporting segfaults as python errors, so I'm a little out of my element here.
➜ python
Python 2.7.9 |Anaconda 1.9.1 (x86_64)| (default, Dec 15 2014, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import astropy
>>> astropy.__version__
u'1.0'
>>> import numpy
>>> numpy.__version__
'1.9.2'
I will definitely now update to the new astropy version, I didn't realize that my issue had been possibly already solved! Thanks for the quick reply!
There are two instances where I had been hitting the segfault: one where I was reading in a table from disk, and one where I was using astropy.table.Table.read() to turn a list of strings into an astropy table.
Once I update, I'll let you know if I get this issue anymore. (The frustrating thing is that the segfault was definitely non-deterministic; sometimes I could run the literal same code twice, and have it crash on the second time after running it cleanly the first time.)
@tomr-stargazer - thanks - does the issue happen systematically, or sporadically? Could you post here the header from python -c 'import astropy; astropy.test()', just so we can see all the system info, etc.?
The issue happens systematically in the following sense:
When I open up the ipython --pylab interpreter and run some production scripts that involve reading files in, I encounter a segfault on-average 50% of the times. The other 50% of the time, the code seems to execute as expected, with no error. (It's bizarre.)
Sometimes, the code will segfault on the first try; sometimes, it will work fine in the first time it's run in the interpreter, but then I re-run the same code (call the same function with the same arguments) and cause a segfault.
One more comment: some of my scripts actually predate astropy, and I had been using atpy.Table(filename, type='ascii') without any segfaults. I understand that atpy now uses astropy internally, and it's only since that migration that I noticed these segfaults occurring.
Horrifically, it still segfaults with fast_reader=False:
# I have put a pdb.set_trace above the offending line of code --->kd_output=astropy.table.Table.read(lines_of_data, format='ascii', fast_reader=False)
(Pdb) c/Users/tsrice/anaconda/bin/python.app: line3: 40792Segmentationfault: 11/Users/tsrice/anaconda/python.app/Contents/MacOS/python"$@"
Somewhat unrelated to this, but I just noticed something interesting--when format is unspecified for a basic text file, the slow reader takes precedence over the fast reader! @taldcroft - was this an intended change? If not, I can open a new PR to change it. The culprit seems to be this line. EDIT: regardless of whether or not this was intended, I think this is a good indication that we need a test somewhere ensuring that the fast reader is called when fast_reader=True.
In terms of this issue, I guess it isn't the fast reader at fault. I have no serious idea of what it could be at the moment--maybe a memory issue?
I linked to a crash log above, with this possibly-relevant section excerpted:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000010beefd0d
VM Regions Near 0x10beefd0d:
MALLOC_LARGE 000000010beb5000-000000010beda000 [ 148K] rw-/rwx SM=COW
-->
MALLOC_TINY 000000010bf00000-000000010c100000 [ 2048K] rw-/rwx SM=PRV
which seems to bolster the idea from @mdmueller that it's a memory issue. (Caveat: I don't work with C code or such crash logs very often, so I may have totally misinterpreted this.)
In the meantime, while this remains open, does anyone have suggestions for how I can turn a list of strings into an astropy.table.Table without having to rely on the buggy astropy.table.Table.read(..., format='ascii')? Perhaps numpy.loadtxt might help out?
Yes, numpy.loadtxt should work, though you will have to specify the data types in the table (or else use genfromtxt with dtype=None). Another thing to try, if you haven't already, is giving a specific format to Table.read, such as format="basic" or format="fixed_width". Not all formats have fast readers, but if you specify one of the "fast" formats it should go directly to the fast reader. I'm curious if this problem exists for the fast reader as well
Note that you have to add the prefix ascii. if you use Table.read, so e.g. format='ascii.fixed_width' (unlike if you use ascii.read where format='fixed_width' is fine)
Hi @astrofrog@mdmueller, when I use format='ascii.no_header' (a special case of ascii.basic if I understand correctly), my segfault issues completely go away (for one of the two cases where I was having problems). So - in that instance, switching ascii readers solved my problem.
In the other case, (where I had some old legacy code using atpy), the problem is more intermittent and it's not critical that I solve it. So - my immediate concerns are gone now.
I think this is going to be related once again to the fact that guessing takes up a lot more memory than the final table will take, and I'm not sure if there's much we can do about that :-/
@astrofrog@taldcroft or anyone else: do you have a good idea what to do with these old issues? They may have been gone as there was no new comments in the last 4 years on this, it was difficult to reproduce though, so they still may be there.
Activity
tomr-stargazer commentedon Mar 21, 2015
Also, version information:
astrofrog commentedon Mar 21, 2015
@tomr-stargazer - could you provide example files that have definitely crashed in the past, even if the error is non-deterministic? Note that there were some segfaults that were fixed in astropy 1.0.1 so you might want to try updating: https://github.com/astropy/astropy/blob/master/CHANGES.rst#101-2015-03-06
tomr-stargazer commentedon Mar 21, 2015
Hi Tom,
I will definitely now update to the new astropy version, I didn't realize that my issue had been possibly already solved! Thanks for the quick reply!
There are two instances where I had been hitting the segfault: one where I was reading in a table from disk, and one where I was using astropy.table.Table.read() to turn a list of strings into an astropy table.
Table from disk:https://gist.github.com/tomr-stargazer/50bd41566cb35434c21a/Actually this one:
https://gist.github.com/tomr-stargazer/8617fee62c1190e81e62
Table from list of strings:
https://gist.github.com/tomr-stargazer/4c378e741ec70575b4da
Once I update, I'll let you know if I get this issue anymore. (The frustrating thing is that the segfault was definitely non-deterministic; sometimes I could run the literal same code twice, and have it crash on the second time after running it cleanly the first time.)
tomr-stargazer commentedon Mar 21, 2015
Okay, I've upgraded to astropy 1.0.1, but I am still able to reproduce the segfault in my production code.
So it seems that my bug was not fixed here.
astrofrog commentedon Mar 21, 2015
@tomr-stargazer - thanks - does the issue happen systematically, or sporadically? Could you post here the header from
python -c 'import astropy; astropy.test()', just so we can see all the system info, etc.?tomr-stargazer commentedon Mar 21, 2015
tomr-stargazer commentedon Mar 21, 2015
The issue happens systematically in the following sense:
When I open up the ipython --pylab interpreter and run some production scripts that involve reading files in, I encounter a segfault on-average 50% of the times. The other 50% of the time, the code seems to execute as expected, with no error. (It's bizarre.)
Sometimes, the code will segfault on the first try; sometimes, it will work fine in the first time it's run in the interpreter, but then I re-run the same code (call the same function with the same arguments) and cause a segfault.
astrofrog commentedon Mar 21, 2015
@tomr-stargazer - just to check, did you install astropy with
conda?tomr-stargazer commentedon Mar 21, 2015
Yes.
astrofrog commentedon Mar 21, 2015
@mdmueller @taldcroft - any idea how to go about debugging this?
tomr-stargazer commentedon Mar 21, 2015
One more comment: some of my scripts actually predate astropy, and I had been using atpy.Table(filename, type='ascii') without any segfaults. I understand that atpy now uses astropy internally, and it's only since that migration that I noticed these segfaults occurring.
mdmueller commentedon Mar 21, 2015
Hm, it's probably something with the fast reader...I can't reproduce this myself. Have you tried reading with
fast_reader=False?tomr-stargazer commentedon Mar 21, 2015
Horrifically, it still segfaults with
fast_reader=False:mdmueller commentedon Mar 21, 2015
Somewhat unrelated to this, but I just noticed something interesting--when
formatis unspecified for a basic text file, the slow reader takes precedence over the fast reader! @taldcroft - was this an intended change? If not, I can open a new PR to change it. The culprit seems to be this line. EDIT: regardless of whether or not this was intended, I think this is a good indication that we need a test somewhere ensuring that the fast reader is called whenfast_reader=True.In terms of this issue, I guess it isn't the fast reader at fault. I have no serious idea of what it could be at the moment--maybe a memory issue?
tomr-stargazer commentedon Mar 21, 2015
I linked to a crash log above, with this possibly-relevant section excerpted:
which seems to bolster the idea from @mdmueller that it's a memory issue. (Caveat: I don't work with C code or such crash logs very often, so I may have totally misinterpreted this.)
tomr-stargazer commentedon Mar 23, 2015
In the meantime, while this remains open, does anyone have suggestions for how I can turn a list of strings into an
astropy.table.Tablewithout having to rely on the buggyastropy.table.Table.read(..., format='ascii')? Perhapsnumpy.loadtxtmight help out?mdmueller commentedon Mar 23, 2015
Yes,
numpy.loadtxtshould work, though you will have to specify the data types in the table (or else usegenfromtxtwithdtype=None). Another thing to try, if you haven't already, is giving a specific format toTable.read, such asformat="basic"orformat="fixed_width". Not all formats have fast readers, but if you specify one of the "fast" formats it should go directly to the fast reader. I'm curious if this problem exists for the fast reader as wellastrofrog commentedon Mar 23, 2015
Note that you have to add the prefix
ascii.if you useTable.read, so e.g.format='ascii.fixed_width'(unlike if you useascii.readwhereformat='fixed_width'is fine)mdmueller commentedon Mar 23, 2015
Oops my mistake, thanks @astrofrog.
embray commentedon Mar 24, 2015
OSX has a ton of memory allocation/management bugs. I wouldn't be surprised if this isn't an Astropy issue at all.
tomr-stargazer commentedon Mar 25, 2015
Hi @astrofrog @mdmueller, when I use
format='ascii.no_header'(a special case ofascii.basicif I understand correctly), my segfault issues completely go away (for one of the two cases where I was having problems). So - in that instance, switching ascii readers solved my problem.In the other case, (where I had some old legacy code using
atpy), the problem is more intermittent and it's not critical that I solve it. So - my immediate concerns are gone now.astrofrog commentedon Mar 25, 2015
I think this is going to be related once again to the fact that guessing takes up a lot more memory than the final table will take, and I'm not sure if there's much we can do about that :-/
cc @taldcroft
bsipocz commentedon Mar 18, 2019
@astrofrog @taldcroft or anyone else: do you have a good idea what to do with these old issues? They may have been gone as there was no new comments in the last 4 years on this, it was difficult to reproduce though, so they still may be there.
taldcroft commentedon Mar 18, 2019
I think we can close those, the code has changed a lot and there are new options like using chunked reading or the pandas backends.