Skip to content

idea - Procedural source/drain for gauche.process redirection #1199

@shirok

Description

@shirok

In run-process of gauche.process, allow a procedure that takes input/output port in the redirector, i.e. (<< fd procedure) calls procedure with an output port, in a separate thread, and the data written to the given port will be fed to the process. So as (>> fd procedure).

It can be done currently by hand-wiring process-input/process-output with threads. Just make it easier. One supposed application is to pass a logging procedure to log the process output.

Issues:

  • What if the thread raises unhandled error? If we do nothing, the error is silently held in the therad until it is joined, which is not desirable---the caller won't know an error is occurred. One plausible solution is that if the procedure raises an unhandled error, immediately kill the process then raises an exception that wraps the original error (parallel to the operation that pipelined process are killed when one of the process exits abnormally). We also want the threads to be properly taken care of after the process exits.
  • Sometimes the handler procedure wants to take care of more than one process i/o (e.g. both stdout and stderr). If we can mix it, we can use (>& fd0 fd1) redirection, but we may want to distinguish them. Of course, the caller can fall back to manual wiring.

The question probably comes down to "is it worith it?" Especially considering the comlication of handling the threads, there should be a strong evidence that this addition makes enough use cases easier. I leave this as an idea until we see such use cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions