I wanted to use eval on threads. I want to catch and restart thread.
This is what I have tried and it does not work. I open file that can't be opened and the thread dies. Is there a better way to do this. All I want to do is thread to log error and restart if something happened.
my $thr = threads->create ( sub { while (1) { eval { while (1) { worker(); } }; if ($@) { print "Error Occured: <$@>.\n"; $@=(); sleep (1); } } } ) sub worker { open FILE_OUT, "> /root/xyz" or die "Can't open file: $!"; }
In reply to Eval thread and restart it. by mr_p
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |