I have a set of Ruby daemons that, on startup, write information in a table of running daemons. The daemons run forever or until they receive a signal. A signal handler deletes the daemon's record in the database. Prior to Ruby 2.0 that worked fine. Since 2.0 I get the error lock': can't be called from trap context (ThreadError)
. Investigation indicates that Ruby disallows this (and logging) in a signal handler as it can introduce race and deadlock conditions. Fair enough. But it seems that what I'm looking to do is reasonable. So what's the right way to do this? Setting a flag and polling seems really ugly. Surely there's a better way.
Asked
Active
Viewed 249 times
2

RussK
- 199
- 1
- 17
-
Basically I'm asking whether it's possible to build a Rails-based daemon with Ruby 2.0 that can clean up gracefully on, say Ctrl-C. So no answers means you can't do this? That seems very limiting for Ruby 2.0. – RussK Jul 02 '13 at 13:48