本文整理汇总了Python中Server.Server.close方法的典型用法代码示例。如果您正苦于以下问题:Python Server.close方法的具体用法?Python Server.close怎么用?Python Server.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Server
的用法示例。
在下文中一共展示了Server.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import close [as 别名]
class Arma2AutoJoin:
server_mon = None
def __init__(self, host, port, mod, arma_path, oa_path, cpucount=None, exthreads=None, maxmem=None):
self.host = host
self.port = port
self.mod = mod
self.arma_path = arma_path
self.oa_path = oa_path
self.cpucount = cpucount
self.exthreads = exthreads
self.maxmem = maxmem
self.server_mon = Server(self.host, self.port)
def connect(self):
os.chdir(self.oa_path)
exe_str = r"expansion\beta\arma2oa.exe"
mod_str = r"-mod=%s;EXPANSION;ca" % self.arma_path
mod2_str = r"-mod=Expansion\beta;Expansion\beta\Expansion;%s" % self.mod
params = [
r"-high",
r"-noPause",
r"-nosplash",
r"-skipintro",
r"-world=empty",
]
if self.cpucount:
params.append(r"-cpuCount=%s" % self.cpucount)
if self.exthreads:
params.append(r"-exThreads=%s" % self.exthreads)
if self.maxmem:
params.append(r"-maxmem=%s" % self.maxmem)
network = [r"-connect=%s" % self.host, r"-port=%d" % self.port]
startup = []
startup.append(exe_str)
startup.append(mod_str)
startup.append(mod2_str)
startup.extend(params)
startup.extend(network)
subprocess.call(startup)
def monitor(self, auto_connect=False, max_sleep_time=3, extra_leeway=1):
self.server_mon.connect()
# Get initial info so we can print the hostname
self._query()
print("%s\n" % self.server_mon.info['hostname'])
max_players = int(self.server_mon.info['maxplayers'])
old_cur_players = 0
while True:
cur_players = int(self.server_mon.info['numplayers'])
if old_cur_players != cur_players:
old_cur_players = cur_players
print("Players: %d/%d" % (cur_players, max_players), end='\r')
if auto_connect and cur_players < (max_players - extra_leeway):
break
time.sleep(random.random() * (max_sleep_time - 1) + 1) # Sleep between 1 and 'sleep_time' seconds
self._query()
self.server_mon.close()
if auto_connect:
self.connect()
def _query(self):
while True:
try:
self.server_mon.query()
except:
print("Server not responding. Retrying in 5 seconds..")
time.sleep(5)
else:
break