Is there an easy way to daemonize a thread?

61 views
Skip to first unread message

David Storrs

unread,
May 19, 2020, 12:02:10 PM5/19/20
to Racket Users
I'm using the file-watchers module to keep an eye on a directory tree and trigger various actions whenever something changes.  I had an issue where an exception was thrown, the thread died, and file watching therefore stopped.  The immediate solution is to wrap a with-handlers around it so it doesn't end up killing the thread, but this made me wonder if there's an easy way to do this automatically?

What I'm thinking of is "Create a thread that will do something in a loop.  Ensure that the thread remains running and restart it if it dies for any reason.  Also, make sure that it runs periodically."  I can think of a solution involving multiple threads, channels, and polling to ensure that the 'daemonized' threads are running, but I was wondering if there's a built-in or existing answer.

George Neuner

unread,
May 19, 2020, 5:28:54 PM5/19/20
to racket...@googlegroups.com
There is a package called "thread-utils" which claims error safe
looping threads.
https://pkgs.racket-lang.org/package/thread-utils

*Disclaimer* I have never tried it.


I can think of a some possible implementations, but they all involve
monitoring by a separate thread (which could be the main thread).
Channels aren't necessary - monitoring can be done using events.

Restarting a (possibly failed) computation IN a running thread is
relatively simple - if you know what errors or events might occur. The
problem is that a thread can't restart itself if somehow it gets
suspended or killed.

George

David Storrs

unread,
May 19, 2020, 9:11:54 PM5/19/20
to Racket Users
Perfect, thank you.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/uvi8cftuuvfkq0cqm27m0icvhhq5mpupuo%404ax.com.

Greg Hendershott

unread,
May 21, 2020, 1:52:57 PM5/21/20
to Racket Users
Maybe I need more coffee, but a possible heads-up: The current implementation doesn't seem to match the documentation -- wouldn't the with-handlers need to move inside the loop, for it to be infinite?

Perfect, thank you.

To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages