What's the rationale for Awk not printing a diagnostic message, but >Genie/Algol 68 does?
Picking just an initial sequence of the created output lines issues an
error diagnostic:
$ genie -x 'FOR i TO 2000 DO print ((i, newline)) OD' | head -2
+1
+2
a68g: exiting: action failed (a68g-bits.c: 196, sigpipe_handler)
And defining event handler (say, 'on transput error' or 'on file end')
in the Genie Algol 68 source doesn't catch that diagnostic, it seems?
Usually I'm annoyed by such diagnostics in application cases like the
pipe constructs on OS/shell level.
Should there be a diagnostic message or not, should such diagnostic
be interceptable by an event handler or not?
What's the rationale for Awk not printing a diagnostic message, but Genie/Algol 68 does?
On 16/09/2025 15:39, Janis Papanagnou wrote:
Picking just an initial sequence of the created output lines issues an
error diagnostic:
$ genie -x 'FOR i TO 2000 DO print ((i, newline)) OD' | head -2
+1
+2
a68g: exiting: action failed (a68g-bits.c: 196, sigpipe_handler)
And defining event handler (say, 'on transput error' or 'on file end')
in the Genie Algol 68 source doesn't catch that diagnostic, it seems?
Indeed; there is no error in the A68G.
Usually I'm annoyed by such diagnostics in application cases like the
pipe constructs on OS/shell level.
I think the root problem is that there are too many ways a pipe
can fail,
some of which are expected and some not, so that "SIGPIPE" is
being expected to guess whether there has been an error.
I agree with
Richard [nearby article] that the Unix/Linux default is to fail silently,
and that this is commonly [but not always] the appropriate behaviour.
But Marcel seems always to have taken the view that errors should be reported. In cases like the present, it's difficult to know whether
there has been an error or not, so A68G reports the "SIGPIPE" anyway.
I have an impression that it's "head" or Linux that is inconsistent;
note that for small values of 2000 ["FOR i to 20 ..."] or large values
of -2 ["head -1998"] there is no "SIGPIPE". Also, there is no problem reported with "tail" ["... | tail | head -2" or even "tail 3000", or
even "... | head -2 | tail"]. I assume there are differences in what
is buffered, leading to differences in whether "SIGPIPE" is raised?
[...]
Janis Papanagnou <[email protected]> writes:
On 17.09.2025 18:39, Andy Walker wrote:
> I think the root problem is that there are too many ways a pipe
> can fail,
What different ways (that are worthwhile to be reported) are you
thinking about here?
I can't tell what anybody is thinking about anything here, and I have no
idea about how your Algol runtime might actually be implemented, but
perhaps the following story about SIGPIPE and its history might prove helpful:
SIGPIPE is not just signalled when you write to a pipe with no reader, it
is also signalled when you write to a network connection that has been
shut down.
This is arguably a botch on the part of the folks that added networking support to Unix. Network sockets and pipes behave similarly in a lot of situations, so somebody thought that it would be natural to re-use
SIGPIPE for the case of writing to a broken network connection.
Unfortunately the default action for SIGPIPE, which is to silently
terminate the process, isn't suitable for network programming where
network connections get broken all the time. (If I'm doing some
transaction to a remote database, should my process _silently_ exit when
the remote server crashes? Probably not!)
[ Thorough ruminations about implementation; C, Python, Algol 68 ]
I'd be interested to hear some standard use-case examples where an
intercept of the signal to produce a diagnostic message would be
"appropriate behaviour".
In that case I just reconfigure the Python runtime back to the
default Unix SIGPIPE behavior by initially calling signal(SIGPIPE,
SIG_DFL) myself.
You might think that a Python BrokenPipeError exception is just the
direct manifestation of an underlying Unix SIGPIPE signal, but that
is _not_ the case. A BrokenPipeError exception is only raised by the
Python runtime when a call to the write() system call returns an
EPIPE error code. So in fact you can't get a BrokenPipeError unless
SIGPIPE is actually being ignored!
You might think that a Python BrokenPipeError exception is just the
direct manifestation of an underlying Unix SIGPIPE signal, but that
is _not_ the case. A BrokenPipeError exception is only raised by the
Python runtime when a call to the write() system call returns an
EPIPE error code. So in fact you can't get a BrokenPipeError unless
SIGPIPE is actually being ignored!
ldo@theon:~> python3 -c "print('hi there')" | cat /dev/null
Exception ignored on flushing sys.stdout:
BrokenPipeError: [Errno 32] Broken pipe
Note that my one-line Python program does not include any signal()
call to ignore SIGPIPE, yet BrokenPipeError does get raised (and
reported).
On 17.09.2025 18:39, Andy Walker wrote:[...]
On 16/09/2025 15:39, Janis Papanagnou wrote:
Picking just an initial sequence of the created output lines issues an
error diagnostic:
$ genie -x 'FOR i TO 2000 DO print ((i, newline)) OD' | head -2
+1
+2
a68g: exiting: action failed (a68g-bits.c: 196, sigpipe_handler)
I think the root problem is that there are too many ways a pipe>> can fail,What different ways (that are worthwhile to be reported) are you
thinking about here?
Mind that we are speaking about a simple, well understood mechanism;
it's generated if the reading communication partner stopped reading
and terminated or closed the pipe, while the writer continues to
write into the abandoned pipe. If the reader has finished his task
and if the writer produces something that's not asked for any more
I see no pressing need to terminate with an error diagnostic. (What
do we gain by that message in a pipe context?)
[...] If [in the Algol 68 application] a write to
'stdout' fails then it should at least be possible to intercept that
event by the standard "transput" event handlers of Algol 68 or Genie
(IMHO).
[...] Perhaps also worth noting
that the problem is nothing [directly] to do with Algol;
"a68g" is a /C/ program.
[...]
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,071 |
Nodes: | 10 (0 / 10) |
Uptime: | 22:34:55 |
Calls: | 13,750 |
Calls today: | 1 |
Files: | 186,980 |
D/L today: |
13,136 files (3,840M bytes) |
Messages: | 2,422,719 |