Permalink
Browse files

Handle the odd case where lc tries to restart itself.

  • Loading branch information...
tailor
tailor committed Oct 16, 2008
1 parent 051d8b5 commit 905b6ef458035420286b37709e32673e6c988ca2
Showing with 23 additions and 3 deletions.
  1. +23 −3 lib/live_console.rb
View
@@ -51,7 +51,15 @@ def initialize(io_method, opts = {})
# IRB console to new connections. If a thread is already running, this
# method simply returns false; otherwise, it returns the new thread.
def start
- return false if thread
+ if thread
+ if thread.alive?
+ return false
+ else
+ thread.join
+ self.thread = nil
+ end
+ end
+
self.thread = Thread.new {
loop {
Thread.pass
@@ -72,7 +80,15 @@ def start
# running, false otherwise.
def stop
if thread
+ if thread == Thread.current
+ self.thread = nil
+ Thread.current.exit!
+ end
+
thread.exit
+ if thread.join(0.1).nil?
+ thread.exit!
+ end
self.thread = nil
true
else
@@ -83,8 +99,12 @@ def stop
# Restarts. Useful for binding changes. Return value is the same as for
# LiveConsole#start.
def restart
- stop
- start
+ r = lambda { stop; start }
+ if thread == Thread.current
+ Thread.new &r # Leaks a thread, but works.
+ else
+ r.call
+ end
end
private

0 comments on commit 905b6ef

Please sign in to comment.