Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:01:22+00:00 2026-06-11T10:01:22+00:00

I’m trying to start and stop an infinite loop daemon using the daemons gem.

  • 0

I’m trying to start and stop an infinite loop daemon using the daemons gem.

Looking at the home page, I tried (in irb):

require 'daemons'
=>true
task_handle = Daemons.call do
  loop{
    sleep 10
    puts "foo"
  }
end
=> #<Daemons::Application:0x000000043f96d0 ...
task_handle.stop
=> nil
task_handle2 = Daemons.call do
  loop{
    sleep 10
    puts "bar"
  }
end

=>Daemons::RuntimeException: there is already one or more instance(s) of the program running
from /home/bdares/.rvm/gems/ruby-1.9.3-p194/gems/daemons-1.1.9/lib/daemons/application_group.rb:125:in `new_application'
from /home/bdares/.rvm/gems/ruby-1.9.3-p194/gems/daemons-1.1.9/lib/daemons.rb:251:in `call'
from (irb):21

Now, the exact example (#3 on the linked page) I’m looking at makes the first call with the option :multiple => true, but I really only need one daemon to be running at a time (and multiple ones would, in fact, be undesirable).

Is the first daemon still somehow alive and not being GC’d? If so, what am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:01:24+00:00Added an answer on June 11, 2026 at 10:01 am

    I think the misunderstanding here is that daemons do not run in order. By the nature of them, they run in parallel with very little coordination between them. I’m sure you could find Ruby interfaces to System V IPC semaphores to coordinate them, but if you want a job queue, look at something besides Daemons.

    Also, to add to @Sigurd’s answer above, here’s the code in question that implements the :force option (which is conveniently undocumented) (source):

    115: if @applications.size > 0 and not @multiple
    116:         if options[:force]
    117:           @applications.delete_if {|a|
    118:             unless a.running?
    119:               a.zap
    120:               true
    121:             end
    122:           }
    123:         end
    124:         
    125:         raise RuntimeException.new('there is already one or more instance(s) of the program running') unless @applications.empty?
    126:       end
    

    So basically, (zap, as I found in the source, does absolutely nothing), when you specify :force, Daemons will delete all non-running applications from @applications if multiple isn’t set. Otherwise, you get an error. So what that means is that if you don’t specify :force or :multiple, your on a one way street to errors.

    Note: The reason for all of this is that Application#stop doesn’t remove the Daemon from the ApplicationGroup (which is in charge of creating new jobs).

    Note: By the way, it’s bad form in Ruby to use {} for multiline blocks. Use {} only for single line blocks. Use do...end for multiline instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.