Detecting thread exit immediately

Discussion in 'Ruby' started by Martin DeMello, Apr 8, 2005.

  1. From the fxirb code:

    class FXIrb < FXText
    include Singleton
    include Responder

    attr_reader :input

    def FXIrb.init(p, tgt, sel, opts)
    unless @__instance__
    Thread.critical = true
    begin
    @__instance__ ||= new(p, tgt, sel, opts)
    ensure
    Thread.critical = false
    end
    end
    return @__instance__
    end

    def create
    super
    setFocus
    # IRB initialization
    @inputAdded = 0
    @input = IO.pipe
    $DEFAULT_OUTPUT = self

    @im = FXIRBInputMethod.new
    @irb = Thread.new {
    IRB.start_in_fxirb(@im)

    #------------------------------
    # INSERT CODE HERE
    #------------------------------
    }
    end

    # -------------------------------------------------------------

    I want to put something in INSERT CODE HERE that will call a method in
    the main thread when IRB.start_in_fxirb returns (i.e. just before the
    other thread dies), rather than having to wait for the GC to collect the
    the thread and then put in a check for @irb.alive?. Is there any good
    way to do this? (What I'm trying to do is have some way for the fxirb
    widget to notify the program containing it that the irb session has
    ended. Right now my choices seem to be to call exit (exits everything),
    to sleep(briefly) after I call @irb.run, and then check @irb.alive?
    (annnoying), to call GC.start everytime I call @irb.run and then check
    @irb.alive? (also annoying), or to have the thread itself notify
    something when it dies (but I can't quite think of how to do it).)

    martin
    Martin DeMello, Apr 8, 2005
    #1
    1. Advertising

  2. Martin DeMello wrote:
    > I want to put something in INSERT CODE HERE that will call a method in
    > the main thread when IRB.start_in_fxirb returns (i.e. just before the
    > other thread dies), rather than having to wait for the GC to collect the
    > the thread and then put in a check for @irb.alive?. Is there any good
    > way to do this? (What I'm trying to do is have some way for the fxirb
    > widget to notify the program containing it that the irb session has
    > ended. Right now my choices seem to be to call exit (exits everything),
    > to sleep(briefly) after I call @irb.run, and then check @irb.alive?
    > (annnoying), to call GC.start everytime I call @irb.run and then check
    > @irb.alive? (also annoying), or to have the thread itself notify
    > something when it dies (but I can't quite think of how to do it).)


    In line with your last thought, what about writing something to a queue
    from the irb thread and then periodically (using a chore) reading the
    queue in the main thread?
    Joel VanderWerf, Apr 8, 2005
    #2
    1. Advertising

  3. Joel VanderWerf <> wrote:
    > > @irb.alive? (also annoying), or to have the thread itself notify
    > > something when it dies (but I can't quite think of how to do it).)

    >
    > In line with your last thought, what about writing something to a queue
    > from the irb thread and then periodically (using a chore) reading the
    > queue in the main thread?


    That still won't give me instant feedback, will it? Why I'm so keen on
    this is that I want the FXIrb panel to stop accepting keystrokes the
    instant the IRB interpreter exits. Everything I've tried so far either
    exits the program, or has a brief time where you can type into a
    theoretically exited widget (mostly since I was focusing on
    Thread#alive? based solutions).

    Is there any way I can have FXIrb pass in 'self' to the thread so that
    it can call methods on it?

    martin
    Martin DeMello, Apr 8, 2005
    #3
  4. Martin DeMello <> wrote:
    >
    > Is there any way I can have FXIrb pass in 'self' to the thread so that
    > it can call methods on it?


    The good people on #ruby-lang solved this one :) It's as simple as

    @irb = Thread.new(self) {
    ....
    self.quit_method
    }

    martin
    Martin DeMello, Apr 8, 2005
    #4
    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. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,898
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    65,839
    sandeep1976
    Nov 8, 2006
  3. Ken Adams
    Replies:
    2
    Views:
    1,100
  4. bsobaid
    Replies:
    1
    Views:
    872
    Vladyslav Lazarenko
    Apr 6, 2009
  5. Gildor Oronar
    Replies:
    4
    Views:
    83
Loading...

Share This Page