[racket] Closing down the web server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Oct 12 16:32:03 EDT 2012

On Fri, Oct 12, 2012 at 10:53 AM, Norman Gray <norman at astro.gla.ac.uk> wrote:
>> You could do...
>>
>> (define we (make-will-executor)
>> (will-register we db sql:close)
>> (define we-t (thread (lambda () (will-execute we))))
>>
>> And when the db was unreachable (because its custodian/thread/etc was
>> killed), then the db would be closed. I believe you would have to
>> ensure that we-t is not within the control of the same custodian.
>
> Most useful as a pattern -- thanks again.  Since the relevant 'prove unreachable' happens in the GC, presumably there's no guarantee that the will associated with db will be executed, when the server (in this case) is shut down.  No longer a problem in this case, so I ask purely for the sake of completeness.

Yes. A reference to the db might leak out some how. (You can
trouble-shot that by compiling in backtrace support. It gives a full
memory snapshoter with the ability to view the reference graph.) But
even if it doesn't, it is unlikely that during process shutdown, the
GC will beat "(exit 0)" and discover that the finalizer should run.
You could force this though by having the will executor thread exit
after and have the process wait for the thread to die before it exits.
I've never tried doing something like this but it "should" work.

Jay

-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.