[plt-scheme] custodian + process/ports

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Tue Jul 1 15:43:54 EDT 2008

As the doc says, 'process/ports executes a shell command asynchronously, 
which means is is not under the control of custodian. It seems that you 
need to use 'subprocess instead of 'process/ports to get subprocess 
value, and then use 'subprocess-kill to kill it.

Chongkai


Tom Schouten wrote:
>   
>> I would create my own input port using 'make-input-port, which might  
>> work just as a pipe, but with 'close to close the custodian that control  
>> the gnuplot process.
>>
>> Hope that helps.
>>
>>     
>
> Thanks for the tip. I seem to get it to work for 'close-output-port, but 
> creating a port in the scope of a custodian and then using 
> 'custodian-shutdown-all doesn't seem to shut it down properly.
>
> (require
>  scheme/system
>  scheme/match)
>
> (define (open-gnuplot)
>   (let ((co (current-output-port)))
>     (match
>      (process/ports co #f co "gnuplot")
>      ((list stdout
>             stdin
>             pid
>             stderr
>             control)
>       (make-output-port
>        'gnuplot
>        stdin
>        (lambda (bytes start endx _ __)
>          (write-bytes bytes stdin start endx))
>        (lambda ()
>          (printf "closing gnuplot\n")
>          (close-output-port stdin)
>          (control 'wait)))))))
>
>
>
>
>   
>> (close-output-port (open-gnuplot))
>>     
> closing gnuplot
>
>
>   
>> (define p #f)
>> (define c (make-custodian))
>> (parameterize ((current-custodian c))
>>    (set! p (open-gnuplot)))
>> (custodian-shutdown-all c)
>>     
>
> -> closes only the embedded port (gnuplot process is defunct)
>   



Posted on the users mailing list.