D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
TracePoint
/
Filename :
allow_reentry-c.ri
back
Copy
U:RDoc::AnyMethod[iI"allow_reentry:ETI"TracePoint::allow_reentry;TT:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [ I"8Generally, while a TracePoint callback is running, ;TI"8other registered callbacks are not called to avoid ;TI" confusion from reentrance. ;TI"9This method allows reentrance within a given block. ;TI"EUse this method carefully to avoid infinite callback invocation.;To:RDoc::Markup::BlankLine o; ; [I"3If called when reentrance is already allowed, ;TI"it raises a RuntimeError.;T@o; ; [I"<b>Example:</b>;T@o:RDoc::Markup::Verbatim; [+I"# Without reentry ;TI"# --------------- ;TI" ;TI"2line_handler = TracePoint.new(:line) do |tp| ;TI"= next if tp.path != __FILE__ # Only works in this file ;TI" puts "Line handler" ;TI"$ binding.eval("class C; end") ;TI"end.enable ;TI" ;TI"4class_handler = TracePoint.new(:class) do |tp| ;TI" puts "Class handler" ;TI"end.enable ;TI" ;TI" class B ;TI" end ;TI" ;TI"O# This script will print "Class handler" only once: when inside the :line ;TI"0# handler, all other handlers are ignored. ;TI" ;TI"# With reentry ;TI"# ------------ ;TI" ;TI"2line_handler = TracePoint.new(:line) do |tp| ;TI"= next if tp.path != __FILE__ # Only works in this file ;TI"Q next if (__LINE__..__LINE__+3).cover?(tp.lineno) # Prevent infinite calls ;TI" puts "Line handler" ;TI"A TracePoint.allow_reentry { binding.eval("class C; end") } ;TI"end.enable ;TI" ;TI"4class_handler = TracePoint.new(:class) do |tp| ;TI" puts "Class handler" ;TI"end.enable ;TI" ;TI" class B ;TI" end ;TI" ;TI"Z# This will print "Class handler" twice: inside the allow_reentry block in the :line ;TI",# handler, other handlers are enabled. ;T:@format0o; ; [I"MNote that the example shows the principal effect of the method, but its ;TI"Xpractical usage is for debugging libraries that sometimes require other libraries' ;TI"Qhooks to not be affected by the debugger being inside trace point handling. ;TI"IPrecautions should be taken against infinite recursion in this case ;TI"P(note that we needed to filter out calls by itself from the :line handler, ;TI"0otherwise it would call itself infinitely).;T: @fileI"trace_point.rb;T:0@omit_headings_from_table_of_contents_below0I"(TracePoint.allow_reentry { block } ;T0[ I"();T@JFI"TracePoint;TcRDoc::NormalClass00