Shotgun and Process.fork

23 views
Skip to first unread message

andyl

unread,
Apr 29, 2011, 10:23:27 PM4/29/11
to sina...@googlegroups.com
I have a Sinatra app that does something like this:

    post '/action' do
      pid = Process.fork { sleep 10; do_some_background_stuff; }
      redirect('/another_page')
    end

I like to use Shotgun for development.  But it seems that Shotgun waits for the forked process to end before it redirects.  That makes it unusable for me.

Does anyone know a workaround, so I can use Process.fork in conjunction with Shotgun??

Tx, Andy

andyl

unread,
Apr 29, 2011, 10:31:59 PM4/29/11
to sina...@googlegroups.com
Looks like someone else had the same question: https://groups.google.com/forum/#!topic/sinatrarb/xH2Eml0L-lg

Sorry about the duplication - but I guess that means others have the same question...

By the way - I have gotten this to work find using Phusion Passenger and thin (production mode - no code reloading). 

But I'd like to get this working using Shotgun for development.  (Or - if there was another compatible solution for Shotgun-like code reloading, I'd love to hear about that!)

- Andy

Konstantin Haase

unread,
Apr 30, 2011, 4:05:41 AM4/30/11
to sina...@googlegroups.com
Since shotgun forks for every request on its own and then kills that fork after the request, there is no way to fix this, I guess.

Konstantin

> --
> You received this message because you are subscribed to the Google Groups "sinatrarb" group.
> To post to this group, send email to sina...@googlegroups.com.
> To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.

andyl

unread,
May 1, 2011, 2:03:39 PM5/1/11
to sina...@googlegroups.com
I came up with an example that works.  It relies on the 'daemons' gem.

Here's the gist:
https://gist.github.com/950681

I've tested it with with shotgun/thin, rackup/webrick, rackup/thin, and passenger on Ubuntu 10.10.

- Andy
Reply all
Reply to author
Forward
0 new messages