Threading nightmare

Discussion in 'Ruby' started by Thiago Jackiw, Jan 10, 2007.

  1. The scenario (for test purposes) I'm trying to accomplish when running
    rake on a new Rakefile is:

    1) start a java server (which doesn't have an option to 'daemonize'
    it) and get its pid
    2) interact with the server by sending things or accessing it
    3) stop the server

    I've tried using IO's popen, fork, thread, even sending the server to
    /dev/null when starting it but none of them work as I expected. Once
    the server (step 1) starts it just hangs in there, not letting the
    following steps to run. But if I kill the server (control+c) the step
    2 tries to run and fails because the server is no longer running.

    Any ideas how it can be done?

    Thanks a lot.

    Thiago
     
    Thiago Jackiw, Jan 10, 2007
    #1
    1. Advertising

  2. Thiago Jackiw

    Tim Pease Guest

    On 1/10/07, Thiago Jackiw <> wrote:
    > The scenario (for test purposes) I'm trying to accomplish when running
    > rake on a new Rakefile is:
    >
    > 1) start a java server (which doesn't have an option to 'daemonize'
    > it) and get its pid
    > 2) interact with the server by sending things or accessing it
    > 3) stop the server
    >
    > I've tried using IO's popen, fork, thread, even sending the server to
    > /dev/null when starting it but none of them work as I expected. Once
    > the server (step 1) starts it just hangs in there, not letting the
    > following steps to run. But if I kill the server (control+c) the step
    > 2 tries to run and fails because the server is no longer running.
    >


    If you're on a non-Windows system, then you can use Ara's "slave" gem.

    Check out Ara's "systemu" gem as well -- although I do not think it
    allows you to send information to the forked process.

    Blessings,
    TwP
     
    Tim Pease, Jan 10, 2007
    #2
    1. Advertising

  3. Tim,

    I'm on a unix box but I'm trying to accomplish this without having to
    be system specific. If I have no choice than I'll have to do it only
    for *nix systems.

    Thiago

    On 1/10/07, Tim Pease <> wrote:
    > On 1/10/07, Thiago Jackiw <> wrote:
    > > The scenario (for test purposes) I'm trying to accomplish when running
    > > rake on a new Rakefile is:
    > >
    > > 1) start a java server (which doesn't have an option to 'daemonize'
    > > it) and get its pid
    > > 2) interact with the server by sending things or accessing it
    > > 3) stop the server
    > >
    > > I've tried using IO's popen, fork, thread, even sending the server to
    > > /dev/null when starting it but none of them work as I expected. Once
    > > the server (step 1) starts it just hangs in there, not letting the
    > > following steps to run. But if I kill the server (control+c) the step
    > > 2 tries to run and fails because the server is no longer running.
    > >

    >
    > If you're on a non-Windows system, then you can use Ara's "slave" gem.
    >
    > Check out Ara's "systemu" gem as well -- although I do not think it
    > allows you to send information to the forked process.
    >
    > Blessings,
    > TwP
    >
    >
     
    Thiago Jackiw, Jan 10, 2007
    #3
  4. Thiago Jackiw

    Tim Pease Guest

    On 1/10/07, Thiago Jackiw <> wrote:
    > Tim,
    >
    > I'm on a unix box but I'm trying to accomplish this without having to
    > be system specific. If I have no choice than I'll have to do it only
    > for *nix systems.
    >


    Also, check out popen4. There is a Windows version and Unix version.
    Both do what you need, but you'll have platform specific code in your
    script.

    Blessings,
    TwP
     
    Tim Pease, Jan 11, 2007
    #4
  5. Thiago Jackiw

    Guest

    On Thu, 11 Jan 2007, Thiago Jackiw wrote:

    >> > The scenario (for test purposes) I'm trying to accomplish when running
    >> > rake on a new Rakefile is:
    >> >
    >> > 1) start a java server (which doesn't have an option to 'daemonize'
    >> > it) and get its pid
    >> > 2) interact with the server by sending things or accessing it
    >> > 3) stop the server


    you don't have an easy choice. if you want to interact you'll want to be unix
    specifc.

    how do you want to interact? via stdin/stdout? does the process need to be a
    daemon or should it depend on the process controlling it also existing? is
    the controlling process transient or permanent?

    >> > I've tried using IO's popen, fork, thread, even sending the server to
    >> > /dev/null when starting it but none of them work as I expected.


    does the server allow itself to run without a tty? some programs don't and
    then you'll need to use the ruby pty lib. this would also limit you to unix.

    > Once the
    >> > server (step 1) starts it just hangs in there, not letting the following
    >> > steps to run.


    is it waiting for input?

    > But if I kill the server (control+c) the step 2 tries to
    >> > run and fails because the server is no longer running.


    makes sense...


    regards.

    -a
    --
    in the practice of tolerance, one's enemy is the best teacher.
    - the dalai lama
     
    , Jan 11, 2007
    #5
  6. Thanks for the help, but I was able to accomplish it using a
    combination of fork, STDERR and exec and it seems to be working fine.

    Thiago


    On 1/11/07, <> wrote:
    > On Thu, 11 Jan 2007, Thiago Jackiw wrote:
    >
    > >> > The scenario (for test purposes) I'm trying to accomplish when running
    > >> > rake on a new Rakefile is:
    > >> >
    > >> > 1) start a java server (which doesn't have an option to 'daemonize'
    > >> > it) and get its pid
    > >> > 2) interact with the server by sending things or accessing it
    > >> > 3) stop the server

    >
    > you don't have an easy choice. if you want to interact you'll want to be unix
    > specifc.
    >
    > how do you want to interact? via stdin/stdout? does the process need to be a
    > daemon or should it depend on the process controlling it also existing? is
    > the controlling process transient or permanent?
    >
    > >> > I've tried using IO's popen, fork, thread, even sending the server to
    > >> > /dev/null when starting it but none of them work as I expected.

    >
    > does the server allow itself to run without a tty? some programs don't and
    > then you'll need to use the ruby pty lib. this would also limit you to unix.
    >
    > > Once the
    > >> > server (step 1) starts it just hangs in there, not letting the following
    > >> > steps to run.

    >
    > is it waiting for input?
    >
    > > But if I kill the server (control+c) the step 2 tries to
    > >> > run and fails because the server is no longer running.

    >
    > makes sense...
    >
    >
    > regards.
    >
    > -a
    > --
    > in the practice of tolerance, one's enemy is the best teacher.
    > - the dalai lama
    >
    >
     
    Thiago Jackiw, Jan 11, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave

    Datagrid PageCount Nightmare!!

    Dave, Nov 13, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,576
  2. Replies:
    5
    Views:
    370
  3. Replies:
    9
    Views:
    1,075
    Mark Space
    Dec 29, 2007
  4. Steven Woody
    Replies:
    0
    Views:
    441
    Steven Woody
    Jan 9, 2009
  5. Steven Woody
    Replies:
    0
    Views:
    464
    Steven Woody
    Jan 9, 2009
Loading...

Share This Page