Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use spoon to execute a ruby block like fork does? #15

Closed
ramarnat opened this issue Aug 26, 2013 · 4 comments
Closed

How can I use spoon to execute a ruby block like fork does? #15

ramarnat opened this issue Aug 26, 2013 · 4 comments

Comments

@ramarnat
Copy link

I am looking to update some code that uses fork so it's compatible with JRuby. The code runs a fork with a block of code, how do I accomplish the same functionality with spoon? I think I have to kick off another jruby instance, but how do I have it hone in on running a particular block?

This is from the aws simple workflow sdk btw.

 class ForkingExecutor 
     def execute(&block)
        @log.error "Here are the pids that are currently running #{@pids}"
        raise RejectedExecutionException if @is_shutdown
        block_on_max_workers
        @log.debug "PARENT BEFORE FORK #{Process.pid}"
        child_pid = fork do
          begin
            @log.debug "CHILD #{Process.pid}"
            # TODO: which signals to ignore?
            # ignore signals in the child
            %w{ TERM INT HUP SIGUSR2 }.each { |signal| Signal.trap(signal, 'SIG_IGN') }
            block.call
            @log.debug "CHILD #{Process.pid} AFTER block.call"
            Process.exit!(0)
          rescue => e
            @log.error e
            @log.error "Definitely dying off right here"
            Process.exit!(1)
          end
        end
        @log.debug "PARENT AFTER FORK #{Process.pid}, child_pid=#{child_pid}"
        @pids << child_pid
      end
end

worker = WorkflowWorker.new(@swf.client, @domain, task_list)
forking_executor = ForkingExecutor.new
forking_executor.execute { worker.start }
@headius
Copy link
Owner

headius commented Aug 26, 2013

There's no way to spawn a subprocess using a block of code under JRuby, even with the spoon gem. However, it should be simple to replace this code with a thread that runs the logic and then terminates itself. You'd get the same concurrency without spawning.

@ramarnat
Copy link
Author

thanks for the quick reply!

the workers need to run as separate processes, so I think I will follow the pattern laid out by foreman by using a runner as laid out here - ddollar/foreman#140

@ramarnat
Copy link
Author

Looking down another path, I found your gist https://gist.github.com/headius/1378616

But it doesn't work in 1.7.4, expected?

@ramarnat
Copy link
Author

got further by using java.util.concurrent.ThreadPoolExecutor as you suggested, but now looks like I hit a wall with this JRuby bug - http://jira.codehaus.org/browse/JRUBY-7188

giving up and going back to MRI for now :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants