5 ms·
What about checking how language implementations solve this for their 'closes' ?
by swah 15y ago
What about checking how language implementations solve this for their 'closes' ?
- nknight 15y agoI assume you're talking about dynamic languages like Python or Ruby. It's common for underlying system characteristics to leak through the abstractions, so something like this isn't necessarily "handled". In CPython's case, as far as I can tell, it uses bare, unchecked close() calls, and just assumes they succeed. (It does, however, provide an interface for dealing with signals, and one of the capabilities, as of 2.6, is to specify whether system calls will restart. See some discussion on SA_RESTART elsewhere in these comments.)
- viraptor 15y agoIf you mean different other languages, that's interesting... Python seems to be completely oblivious to the issue and signals (Modules/_io/fileio.c internal_close() and others). There is SA_RESTART added if possible in Modules/faulthandler.c - but I'm not sure what conditions activate it.
- saurik 15y agoYeah. This can be a serious issue, for the record. It is difficult for me to come up with an experience that has made me quite as angry as calling urllib.urlopen().read() in a highly-contended program (Apache2 mpm_worker) and getting an EINTR exception bubbled all the way up to the top... I mean, what did they expect I do: retry the entire HTTP fetch? ;P I finally switched to mpm_event, which caused me to no longer get signals constantly, but until then I was seriously running a patched copy of Python to work around this issue; an issue, by the way, which was reported at the beginning of 2007, and only fixed midway through 2010. :( http://bugs.python.org/issue1628205 http://bugs.python.org/issue1628205 The general idea, however, is that if you are using a low-level primitive, one that nigh unto maps directly to a system call (as opposed to urlopen ;P), then you actually "want" (supposedly) EINTR to not be handled for you, as it might be your intention to use it to do something valuable (just as you might from a C program).
- swah 15y agoSorry for the confusion - but yes, I meant languages implemented in C or C++ (Java, Factor, Python..)
- __david__ 15y agoPerl seems to do this (PerlIOUnix_close() in perlio.c)[1]: while (PerlLIO_close(fd) != 0) { if (errno != EINTR) { code = -1; break; } /* EINTR */ if (PL_sig_pending && S_perlio_async_run(aTHX_ f)) return -1; } [1] https://github.com/mirrors/perl/blob/be48bbe8d671b6841c3ec7cb734b98071afe3cd9/perlio.c#L2859 https://github.com/mirrors/perl/blob/be48bbe8d671b6841c3ec7c...