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

Using the guard thread correctly #25

Open
ploubser opened this issue Jun 21, 2013 · 0 comments
Open

Using the guard thread correctly #25

ploubser opened this issue Jun 21, 2013 · 0 comments

Comments

@ploubser
Copy link

I am struggling to figure out how to correctly use systemu in a multithreaded environment. The use case is as follows.

I have a runner loop that will spawn any number on threads, where each of them could possibly make a call to systemu. The implementation on my side looks like this.

      thread = Thread.current
      @status = systemu(@command, opts) do |cid|
        begin
          while(thread.alive?)
            sleep 0.1
          end

          Process.waitpid(cid) if Process.getpgid(cid)

        rescue SystemExit
        ...

The goal here is to use the thread spawned by systemu to prevent defunct processes.

So the problem is, if the thread that made the call to systemu dies, there obviously is no way for the exit code to make it back to the main thread, leaving me with nil's.

Also, even with the guard thread attempting to clean up defunct processes, I still have users reporting them.

Am I missing something obvious? Any feedback will be greatly appreciated.

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

1 participant