Pregunta

Tengo un script Ruby que hace unas pocas operaciones forzosamente (a través de la API de scripting) luego termina simplemente:

def foo()
  ...
end

def bar()
  ...
end

foo()
bar()
puts __LINE__
exit 0
#end of file

... y mientras el LINEA imprimirá, el proceso nunca termina, ya sea la salida (0) está allí o no. Este es el rubí 1.8.6, principalmente en el mac, pero estoy viendo esto en el PC también.

Estoy haciendo lo habitual hurgando Google, pero la esperanza de que podría haber una voz de la experiencia aquí para depositar en. Gracias.

¿Fue útil?

Solución

No estoy en absoluto familiarizados con fuerza, pero el culpable podría ser un método at_exit que está atrapado en un bucle por alguna razón. Observar el comportamiento usando irb, por ejemplo:

$ irb
irb(main):001:0> require 'time'
=> true
irb(main):002:0> at_exit { puts Time.now; sleep 10; puts Time.now }
=> #<Proc:0xb7656f64@(irb):2>
irb(main):003:0> exit
Fri Mar 12 19:46:25 -0500 2010
Fri Mar 12 19:46:35 -0500 2010

Para confirmar si una función at_exit está causando el proceso para colgar, puede intentar enganchar en at_exit. Tenga en cuenta que la #{caller} mostrará el seguimiento de la pila de quien llama at_exit:

def at_exit &block
    @at_exit_counter ||= 0
    puts "at_exit #{@at_exit_counter} called"
    s = "Calling at_exit ##{@at_exit_counter} from #{caller}"
    super { puts s; block.call() }
    @at_exit_counter += 1
end

at_exit { puts "I'll never return"; sleep 1 while true; }
at_exit { puts 'I am about to leave.' }

def do_cleanup
    puts "Cleaning..."
    at_exit { puts 'Cleaning up before exit...' }

end

do_cleanup

que emite:

at_exit 0 called
at_exit 1 called
Cleaning...
at_exit 2 called
Calling at_exit #2 from exitcheck.rb:14:in `do_cleanup'exitcheck.rb:18
Cleaning up before exit...
Calling at_exit #1 from exitcheck.rb:10
I am about to leave.
Calling at_exit #0 from exitcheck.rb:9
I'll never return

y nunca regresa.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top