Re: [racket-users] Re: Is there an easy way to daemonize a thread?

2020-05-21 Thread Greg Hendershott
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?

https://github.com/Kalimehtar/thread-utils/blob/master/main.rkt#L35-L41

On Tuesday, May 19, 2020 at 9:11:54 PM UTC-4, David Storrs wrote:
>
> Perfect, thank you.
>
> On Tue, May 19, 2020 at 5:28 PM George Neuner  > wrote:
>
>> On Tue, 19 May 2020 12:01:54 -0400, David Storrs
>> > wrote:
>>
>> >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.
>>
>> 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
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/uvi8cftuuvfkq0cqm27m0icvhhq5mpupuo%404ax.com
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/a1eba505-25f5-4ced-8f40-644fbced1e07%40googlegroups.com.


Re: [racket-users] Re: Is there an easy way to daemonize a thread?

2020-05-19 Thread David Storrs
Perfect, thank you.

On Tue, May 19, 2020 at 5:28 PM George Neuner  wrote:

> On Tue, 19 May 2020 12:01:54 -0400, David Storrs
>  wrote:
>
> >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.
>
> 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
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/uvi8cftuuvfkq0cqm27m0icvhhq5mpupuo%404ax.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKodqJQs__Mj%3DFo9wY77eanS4ReNwrL0zKED1A4_FAFNqBQ%40mail.gmail.com.