更改侦听器脚本以在后台运行在服务器上?

时间:2015-12-08 09:26:39

标签: python event-listener

我已经编写了下面的python脚本以在服务器上运行,并充当来自URI api的json响应更改的侦听器。

import json import time
import requests

class Test():

   def __init__(self):
       self.total_services = self.__get_total_services()

   def __get_total_services(self):
       url = "my_url_that_responds_with_json"
       response = requests.get(url)
       json_data = response.json()
       dict_data = json.loads(json.dumps(json_data))
       total = len(dict_data['services'])
       return total

   def listen_for_changes(self):
      while 1:
           if (self.__get_total_services() != self.total_services):
               """do something"""
               self.total_services = self.__get_total_services()
           time.sleep(60)
       return 0

my_test = Test()
my_test.listen_for_changes()

我的问题是这个代码应该在后台以某种方式运行,还是可以从我的服务器运行它?

0 个答案:

没有答案