On 1/20/2019 6:34 PM, Brian Adkins wrote:
Thanks.
I do use dynamic-wind in various ways now, but I'm not sure how it
would help me in this particular scenario. My log receiver thread is
simply in a loop sync'ing on the logger, so I can't wait for my
thread. I don't know how to determine when all the log messages have
been received. Sleeping for a second would probably do it, but that
seems pretty kludgy :)
You make the the logging thread wait for either a message or a stop
event, and once it receives the 'stop' event, have it empty the message
queue before exiting. E.g.,
:
; loop until stop-evt
(do [
(event (sync receiver stop-evt)
(sync receiver stop-evt))
]
((equal? event stop-evt) 'flush_queue)
(write-one-event event))
; loop until queue empty
(do [
(event (sync/timeout 0.01 receiver)
(sync/timeout 0.01 receiver))
]
((equal? event #f) 'stop)
(write-one-event event))
:
;end of logging thread
At the point you send the stop event, all the messages should have been
posted even if not yet printed.
In the main thread you [call some function to send the stop event and
wait for the logger thread to finish. Where you want to use
dynamic-wind is if the main [or other processing] thread can be
interrupted (Ctrl-C, etc.) - you want to make sure the logger gets shut
down cleanly no matter how the main thread ends.
This is mainly a problem for logging in tests because they can finish
so quickly. For my main application, I don't think it will be much of
an issue. For my tests, I just created a wrapper that uses the default
logger, and I'll control the amount of output with a PLTSTDERR env
variable.
Tests can be a problem anyway because the tests may need significant
setup just like the real program. I pretty much always wrap my code in
a dynamic-wind: regardless of setup, I want to be sure I can clean up
afterwards even if I had to break it.
George
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.