繁体   English   中英

与sinatra一起使用eventmachine,为什么它总是退出?

[英]Use eventmachine with sinatra, why it will always quit?

为什么当我运行这个ruby程序时它总是退出?
这是ruby程序:

require 'rubygems'
require 'eventmachine'
require 'thread'
require 'sinatra'

Thread.new do
    EventMachine.run do
        EM.add_periodic_timer(1) do
            #do some things
        end
    end
end

get '/' do
    'hello'
end

当我运行它时,我得到了:

lynn@ubuntu:~/Test$ ruby em1.rb 
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop
lynn@ubuntu:~/Test$ 
lynn@ubuntu:~/Test$ netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp       28      0 192.168.241.134:38223   91.189.92.11:443        CLOSE_WAIT 
tcp        1      0 192.168.241.134:42978   91.189.94.25:80         CLOSE_WAIT 
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
lynn@ubuntu:~/Test$ 

当我运行这个ruby程序时,它退出了,为什么呢? 在这里,我想要一个线程来周期性地执行http请求! 我该怎么做 ?

只需在thin服务器上运行您的Sinatra应用程序,它将被Eventmachine触发

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM