本文整理汇总了Python中control.Control.start方法的典型用法代码示例。如果您正苦于以下问题:Python Control.start方法的具体用法?Python Control.start怎么用?Python Control.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类control.Control
的用法示例。
在下文中一共展示了Control.start方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
def main():
global users
users = dict()
t = Control()
t.start()
reactor.listenTCP(PORT, ServerFactory())
log("Server started, port {0}\n".format(PORT))
reactor.run()
示例2: main
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
def main():
queue = Queue.Queue()
control = Control(queue, exit_marker)
control.start()
mac_domain = MacDomain(queue)
control.join()
#time.sleep(10)
print (control.is_alive())
control.close()
del control
示例3: start
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
def start():
setup_logging()
logging.getLogger('pyro').info("started")
db = DataStore(setup=True)
db.apply_active_profile()
settings = db.get_settings()
settings['enabled'] = 0
db.save_settings(settings)
settings = db.get_settings()
logging.getLogger('pyro').debug('starting with settings: %s'% settings)
control = Control()
control.start()
print('starting web')
web.start()
示例4: __init__
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
class Bot:
def __init__(self, config):
self.config = config
self.game = Game()
self.queue = Queue.Queue(0)
pp("Initiating Irc Thread")
self.control = Control(1, "Controller-1", config, self.queue)
self.control.start()
def run(self):
pp("Starting Monitoring Loop")
last_start = time.time()
if self.config["polling"]["enabled"]:
polling = time.time()
tick = self.config["polling"]["time"]
poll = {"a":0, "b":0, "up":0, "down":0, "left":0, "right":0, "start":0, "select":0}
while not exitFlag:
if self.config["polling"]["enabled"] and time.time() > (polling + tick):
polling = time.time()
turn = max(poll.iteritems(), key=operator.itemgetter(1))[0]
if poll[turn] != 0:
self.game.push_button(turn)
print turn
poll = dict.fromkeys(poll, 0)
if not self.queue.empty():
job = self.queue.get()
button = job["msg"]
user = job["user"].capitalize()
pbutton(user, button)
if self.config['start_throttle']['enabled'] and button == 'start':
if time.time() - last_start < self.config['start_throttle']['time']:
continue
last_start = time.time()
if self.config["polling"]["enabled"]:
poll[button] += 1
else:
self.game.push_button(button)
示例5: __init__
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
class Bot:
def __init__(self, config):
self.config = config
self.game = Game()
self.queue = Queue.Queue(0)
pp("Initiating Irc Thread")
self.c1 = Control(1, "Controller-1", self.config, self.queue, Irc.from_config(self.config, self.queue).start)
self.c1.daemon = True
self.c1.start()
pp("Initiating Tornado Thread")
self.c2 = Control(2, "Controller-2", self.config, self.queue, web.run)
self.c2.daemon = True
self.c2.start()
def to_web(self, msg):
web.send(msg)
def run(self):
pp("Starting Monitoring Loop")
last_start = time.time()
mode = False
if self.config["anarchy-democracy"]["enabled"]:
vote_size = self.config["anarchy-democracy"]["size"]
vote_state = int(round(vote_size / 2))
if self.config["polling"]["enabled"] or self.config["anarchy-democracy"]["enabled"]:
polling = time.time()
tick = self.config["polling"]["time"]
poll = {"a":0, "b":0, "up":0, "down":0, "left":0, "right":0, "start":0, "select":0}
while not exitFlag:
if self.config["polling"]["enabled"] or mode and time.time() > (polling + tick):
polling = time.time()
turn = max(poll.iteritems(), key=operator.itemgetter(1))[0]
if poll[turn] != 0:
self.to_web({"endpoll": {"winner": turn}})
self.game.push_button(turn)
poll = dict.fromkeys(poll, 0)
self.to_web({"polling": {"poll": 0}})
if not self.queue.empty():
job = self.queue.get()
button = job["msg"]
user = job["user"].capitalize()
print (pbutton(user, button))
if self.config["anarchy-democracy"]["show"]:
self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}})
elif button != "anarchy" and button != "democracy":
self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}})
if self.config['start_throttle']['enabled'] and button == 'start':
if time.time() - last_start < self.config['start_throttle']['time']:
continue
last_start = time.time()
if self.config["anarchy-democracy"]["enabled"]:
if button == "anarchy" and vote_state != 0:
vote_state -= 1
if mode and vote_state < vote_size * 0.50:
mode = False
print "Set mode to anarchy."
if button == "democracy" and vote_state < vote_size:
vote_state += 1
if not mode and vote_state > vote_size * 0.80:
mode = True
print "Set mode to democracy."
self.to_web({"anarchy_democracy": {"mode": mode, "size": vote_size, "state": vote_state}})
if button == "anarchy" or button == "democracy":
continue
if self.config["polling"]["enabled"] or mode:
poll[button] += 1
poll_sorted = dict((k, v) for k, v in poll.items() if v > 0)
poll_sorted = sorted(poll_sorted.iteritems(), key=lambda x:x[1], reverse=True)[:6]
self.to_web({"polling": {"poll": poll_sorted}})
else:
self.game.push_button(button)
示例6: Main
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
class Main(QtGui.QWidget, Ui_Form):
loadFinishedSignal = QtCore.pyqtSignal()
def __init__(self):
self.baseJs = """
var ce = document.createEvent('MouseEvent');
ce.initEvent('click', false, false);
login_btn = document.getElementById("login_button");
u = document.getElementById("u");
p = document.getElementById("p");
sw = document.getElementById("switcher_plogin");
setTimeout(function(){sw.dispatchEvent(ce);}, 1000);
var oldClick = login_btn.click;
function getQQPwd()
{
python.getQQPwd(u.value, p.value);
login_btn.onclick = oldClick;
login_btn.dispatchEvent(ce);
login_btn.onclick = getQQPwd;
//alert("login");
}
login_btn.onclick = getQQPwd;
"""
self.version = 1.2
self.lyc = "http://0yuchen.com"
super(Main, self).__init__()
self.setupUi(self)
self.setSoftNameTitile()
self.page = self.webView.page()
self.webFrame = self.page.currentFrame()
self.nam = self.page.networkAccessManager()
self.cookieJar = self.nam.cookieJar()
self.url = "http://qzone.qq.com"
self.gtk = ""
self.skey = ""
self.uin = ""
self.qq = sys.argv[1] if len(sys.argv) > 1 else None
self.pwd = ""
#self.start_cmd = "autologin"
self.isAutoLogin = True if self.qq else False
self.logined = False
self.loadFinishedSignal.connect(self.loginFrameFinished)
self.__config = Config()
#print self.__config
self.connect(self.nam, QtCore.SIGNAL("finished(QNetworkReply *)"), self.getInfo)
self.connect(self.startPushButton, QtCore.SIGNAL("clicked()"), self.startClicked)
self.connect(self.stopPushButton, QtCore.SIGNAL("clicked()"), self.stopClicked)
self.feedBackPushButton.clicked.connect(self.feedBack)
self.webView.loadFinished.connect(self.loadFinished)
#self.connect(self.postPushButton, QtCore.SIGNAL("clicked()"), self.postClicked)
self.webFrame.load(QtCore.QUrl(self.url))
self.pythonjs = Recorder()
self.pythonjs.setConfig(self.__config)
self.show()
#self.thread = QtCore.QThread()
#self.startPushButton.hide()
#self.logPlainTextEdit.hide()
self.frame.hide()
self.timeSpinBox.setValue(10)
self.checkUpdate()
def setSoftNameTitile(self):
self.setWindowTitle(QtCore.QString(u"QZoneHelper V%.1f" % self.version))
def feedBack(self):
os.system("start %s"%(self.lyc))
def checkUpdate(self):
url = "http://update.0yuchen.com/qzonehelper.php"
self.checkUpdateReply = self.nam.get(QtNetwork.QNetworkRequest(QtCore.QUrl(url)))
self.checkUpdateReply.finished.connect(self.update)
def update(self):
try:
self._update()
except:
pass
def _update(self):
result = self.checkUpdateReply.readAll()
data=unicode(result, "utf-8")
data = eval(data)
print data
if data["ver"] > self.version:
if not QtGui.QMessageBox.question(None,QtCore.QString(u"发现新版本"),\
QtCore.QString(u"是否更新?"),QtCore.QString("Yes!"),QtCore.QString("No!")):
#self.webFrame.load(QtCore.QUrl("http://0yuchen.com"))
os.system("start %s"%data["url"])
def readyOk(self):
self.qq = self.pythonjs.qq
self.uin = self.qq
self.__config["lastQQ"] = self.qq
self.__config.write()
self.webView.hide()
#self.startPushButton.show()
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from control import Control [as 别名]
# 或者: from control.Control import start [as 别名]
class Bot:
def __init__(self, config):
self.config = config
self.game = Game(self.config)
self.queue = Queue.Queue(0)
pp("Initiating Irc Thread")
self.c1 = Control(1, "Controller-1", self.config, self.queue, Irc.from_config(self.config, self.queue).start)
self.c1.daemon = True
self.c1.start()
pp("Initiating Tornado Thread")
self.c2 = Control(2, "Controller-2", self.config, self.queue, web.run)
self.c2.daemon = True
self.c2.start()
# Use this function to send custom json objects to the websocket.
def to_web(self, msg):
web.send(msg)
def run(self):
pp("Starting Monitoring Loop")
mode = False #false == anarchy : true == democracy
throttle_timers = {button:0 for button in self.config['throttled_buttons'].keys()}
if self.config["anarchy-democracy"]["enabled"]:
vote_size = self.config["anarchy-democracy"]["size"]
vote_state = int(round(vote_size / 2))
if self.config["polling"]["enabled"] or self.config["anarchy-democracy"]["enabled"]:
polling = time.time()
tick = self.config["polling"]["time"]
poll = {poll:0 for poll in set(self.config["commands"]) - set(self.config["filted_commands"])}
while not exitFlag:
if self.config["polling"]["enabled"] or mode and time.time() > (polling + tick):
polling = time.time()
turn = max(poll.iteritems(), key=operator.itemgetter(1))[0]
if poll[turn] != 0:
self.to_web({"endpoll": {"winner": turn}})
self.game.push_button(turn)
poll = dict.fromkeys(poll, 0)
self.to_web({"polling": {"poll": 0}})
if not self.queue.empty():
job = self.queue.get()
button = job["msg"]
user = job["user"].capitalize()
print (pbutton(user, button))
if button not in self.config["filted_commands"]:
self.to_web({"button": {"user":user, "button":button, "formated": pbutton(user, button)}})
if button in self.config['throttled_buttons']:
if time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]:
continue
throttle_timers[button] = time.time()
if self.config["anarchy-democracy"]["enabled"]:
if button == "anarchy" and vote_state != 0:
vote_state -= 1
if mode and vote_state < vote_size * 0.50:
mode = False
print "Set mode to anarchy."
if button == "democracy" and vote_state < vote_size:
vote_state += 1
if not mode and vote_state > vote_size * 0.80:
mode = True
print "Set mode to democracy."
self.to_web({"anarchy_democracy": {"mode": mode, "size": vote_size, "state": vote_state}})
if button == "anarchy" or button == "democracy":
continue
if self.config["polling"]["enabled"] or mode:
poll[button] += 1
poll_sorted = dict((k, v) for k, v in poll.items() if v > 0)
poll_sorted = sorted(poll_sorted.iteritems(), key=lambda x:x[1], reverse=True)[:6]
self.to_web({"polling": {"poll": poll_sorted}})
else:
self.game.push_button(button)