multithreading - Thread lockup in ruby with Soap4r -
This is related to a question I asked here:
Although it is special for a part of it Is supported by the question and a simple example. Exam code is:
'rubygems' is required 'thread' is required 'soap / rpc / standalone server' class SOAPServer & lt; SOAP :: RPC :: Standalone server DRF initialization (* AGR) Super # Exposed methods add_method (self, 'test', 'x', 'y') end-diff test (x, y) returns x + y end and mysarver = .New ('Monitor Service', 'Color: Ruby: Monitor Service', 'Localhost', 4004) Thread. New 'MyServer.start' launches web services' sleeps at the end of 'eliminating web services' (4) # Thread.New Do Tasteanum = 0 while Testonum & lt; 4000 do testnum + = 1 myServer.test (0, testnum) sleep (2) end #end says myServer.test (0,4001) myServer.test (0,4002) puts puts myServer.test (0 , 4003) MyServer.test (0,4004) gets
When I run it with the thread, then everything is well understood. However, once the thread is hanging in the process I poked in Webrick and found that the stop is here (puts, of course, mine):
while @status ==: running begins Is "1.1" if svrs = IO.select (@listsers, zero, zero, 2.0) SVR [0] .EEE {| SVR | Puts "- + -" @ tokenspip # blocks while no token is there. If sock = accept_client (svr) th = start_thread (sock, and block) and [: WEBrickThread] = true thgroup.add (th) else @ tokens.push (zero) end} puts ". +."
When the comment is not commented outside the thread, then I get something like this: start web services
1.1. 1.1 4001 4002 4003 4004 1. 1.1
If the problem is happening () calls and the purpose becomes your call in the code To stop Ruby from going out of Ruby Interpreter, you can call it for threads from Thread.Join () that you create. As long as the thread is executed, join () is blocked () and hence it will stop the Ruby interpreter from exiting.
Example:
t1 = Thread.New puts 'web services start' myServer.start 'ending web services' end t2 = .... .. t1.join t2.join
Alternatively, if you can join only one of the () threads if there is a single thread that controls the execution of the application , And other threads will be killed on exit.
Comments
Post a Comment