좋아 메이슨, 그래서 대답은, 두 개의 클래스, 시간을 업데이트 한을 설정했다 타임 스탬프 20 초에 업데이트되지 않은 경우 지속적으로 확인하는 다른. 이것은 전체 사이트가 CherryPy에 구축되지 않은 경우 사용자가 페이지를 떠난 후에 프로세스를 종료하는 데 유용 할 때 매우 유용합니다. 필자의 경우 Zend 프로젝트에서 JS ping을 수신하는 것으로 8080에 간단히 앉아있다. CherryPy 코드는 보이는 같은 :
<script type="text/javascript">
function ping(){
$.ajax({
url: 'http://localhost:8080'
});
}
function initWatcher(){
$.ajax({
url: 'http://localhost:8080/other'
});
}
ping(); //Set time variable first
initWatcher(); //Starts the watcher that waits until the time var is >20s old
setInterval(ping, 15000); //Updates the time variable every 15s, so that while users are on the page, the watcher will never kill the process
</script>
희망이 다른 사람이 사용자가 페이지를 떠나 일단 살인을 처리하기 위해 유사한 솔루션을 찾는 데 도움이 :로 핑은 문자 그대로 간단하다는
import cherrypy
import os
import time
class ProcKiller(object):
@cherrypy.expose
def index(self):
global var
var = time.time()
@cherrypy.expose
def other(self):
while(time.time()-var <= 20):
time.sleep(1)
print var
os.system('pkill proc')
cherrypy.quickstart(ProcKiller())
JS를!
메이슨