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
If socket timeout > 0, then there is no way to automatically
restart some socket calls like recv().
Calling siginterrupt(False) is useless, because python calls
internal_select() if socket has timeout, and select returns
error(EINTR) once interrupted by a signal, regardless of the
SA_RESTART flags.
So a user may have to wrap every socket calls in this case.
"The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:
Victor, I understand your response as saying that there is no bug, which would suggest closing this. Correct? If not, what is the requested action?
neologix commented on Jun 4, 2011
neologixmannequin
Mannequin
More actions
Actually, it's part of a more general problem with EINTR being returned by many posix/socket module functions, see for example issue bpo-7978.
On the one hand, having to retry manually on EINTR is cumbersome, on the other hand, some code might rely on this - receiving EINTR - and the posix module policy is to expose syscalls as-is.
This should probably be closed as duplicate of issue bpo-9867.
Victor, I understand your response as saying that there is no bug,
which would suggest closing this. Correct? If not, what is
the requested action?
siginterrupt(False) has no effect on select().
I listed some solutions to not interrupt select() on a signal (avoid completly EINTR). Issues bpo-7978 and bpo-9867 try the other solution, handle EINTR (retry select() on EINTR). I think that most users prefer the later (handle EINTR), so let's close as a duplicate.
@zhiping Deng: Reopen the issue if you want the first solution :-)
I think the problem is that after a user calles signal.siginterrupt(False),
he would expect that the socket.recv should handles EINTR properly
for him because it's the behaviour in c level.
He doesn't know socket.recv() calles select(2) internally and he needn't.
Or at least this should be documented in signal.siginterrupt().
Activity
ZhipingDeng commentedon May 31, 2011
If socket timeout > 0, then there is no way to automatically
restart some socket calls like recv().
Calling siginterrupt(False) is useless, because python calls
internal_select() if socket has timeout, and select returns
error(EINTR) once interrupted by a signal, regardless of the
SA_RESTART flags.
So a user may have to wrap every socket calls in this case.
I found some related discussions in http://bugs.python.org/issue7978
vstinner commentedon May 31, 2011
Extract of manpage signal(7):
"The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:
Consider siginterrupt(signal, False) as a "best-effort" trick... which doesn't work with select().
If you don't want select() to be interrupted by SIGINT, use:
pthread_sigmask(SIG_BLOCK, [SIGINT]);
select(...)
pthread_sigmask(SIG_UNBLOCK, [SIGINT])
or
pselect() is atomic, whereas pthread_sigmask+select is not.
I added recently pthread_sigmask() to the signal module in Python 3.3.
pselect() is not exposed in Python currently. We may add it if it's needed.
--
If you really don't care of SIGINT, you can also ignore it completly using signal(SIGINT, SIG_IGN).
terryjreedy commentedon Jun 3, 2011
Victor, I understand your response as saying that there is no bug, which would suggest closing this. Correct? If not, what is the requested action?
neologix commentedon Jun 4, 2011
Actually, it's part of a more general problem with EINTR being returned by many posix/socket module functions, see for example issue bpo-7978.
On the one hand, having to retry manually on EINTR is cumbersome, on the other hand, some code might rely on this - receiving EINTR - and the posix module policy is to expose syscalls as-is.
This should probably be closed as duplicate of issue bpo-9867.
vstinner commentedon Jun 4, 2011
siginterrupt(False) has no effect on select().
I listed some solutions to not interrupt select() on a signal (avoid completly EINTR). Issues bpo-7978 and bpo-9867 try the other solution, handle EINTR (retry select() on EINTR). I think that most users prefer the later (handle EINTR), so let's close as a duplicate.
@zhiping Deng: Reopen the issue if you want the first solution :-)
ZhipingDeng commentedon Jun 4, 2011
I think the problem is that after a user calles signal.siginterrupt(False),
he would expect that the socket.recv should handles EINTR properly
for him because it's the behaviour in c level.
He doesn't know socket.recv() calles select(2) internally and he needn't.
Or at least this should be documented in signal.siginterrupt().