本文整理汇总了Python中xpra.dotxpra.DotXpra.server_state方法的典型用法代码示例。如果您正苦于以下问题:Python DotXpra.server_state方法的具体用法?Python DotXpra.server_state怎么用?Python DotXpra.server_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xpra.dotxpra.DotXpra
的用法示例。
在下文中一共展示了DotXpra.server_state方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_stop
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def run_stop(parser, opts, extra_args):
assert "gtk" not in sys.modules
magic_string = bencode(["hello", {"__prerelease_version": xpra.__version__}]) + bencode(["shutdown-server"])
display_desc = pick_display(parser, opts, extra_args)
conn = connect_or_fail(display_desc)
while magic_string:
magic_string = magic_string[conn.write(magic_string):]
while conn.read(4096):
pass
if display_desc["local"]:
sockdir = DotXpra(opts.sockdir)
for _ in xrange(6):
final_state = sockdir.server_state(display_desc["display"])
if final_state is DotXpra.LIVE:
break
time.sleep(0.5)
if final_state is DotXpra.DEAD:
print("xpra at %s has exited." % display_desc["display"])
sys.exit(0)
elif final_state is DotXpra.UNKNOWN:
print("How odd... I'm not sure what's going on with xpra at %s"
% display_desc["display"])
sys.exit(1)
elif final_state is DotXpra.LIVE:
print("Failed to shutdown xpra at %s" % display_desc["display"])
sys.exit(1)
else:
assert False, "invalid state: %s" % final_state
else:
print("Sent shutdown command")
示例2: run_proxy
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def run_proxy(parser, opts, script_file, args, start_server=False):
from xpra.proxy import XpraProxy
assert "gtk" not in sys.modules
if start_server:
assert len(args)==1
display_name = args[0]
#we must use a subprocess to avoid messing things up - yuk
cmd = [script_file, "start"]+args
if opts.start_child and len(opts.start_child)>0:
for x in opts.start_child:
cmd.append("--start-child=%s" % x)
if opts.exit_with_children:
cmd.append("--exit-with-children")
def setsid():
os.setsid()
Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid)
dotxpra = DotXpra()
start = time.time()
while dotxpra.server_state(display_name, 1)!=DotXpra.LIVE:
if time.time()-start>5:
warn("server failed to start after %.1f seconds - sorry!" % (time.time()-start))
return
time.sleep(0.10)
server_conn = connect_or_fail(pick_display(parser, opts, args))
app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn)
signal.signal(signal.SIGINT, app.quit)
signal.signal(signal.SIGTERM, app.quit)
app.run()
return 0
示例3: run_stop
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def run_stop(parser, opts, extra_args):
magic_string = bencode(["hello", []]) + bencode(["shutdown-server"])
display_name = pick_display(parser, extra_args)
sock, local = client_sock(parser, opts, display_name)
sock.sendall(magic_string)
while sock.recv(4096):
pass
if local:
sockdir = DotXpra()
for i in xrange(6):
final_state = sockdir.server_state(display_name)
if final_state is DotXpra.LIVE:
time.sleep(0.5)
else:
break
if final_state is DotXpra.DEAD:
print "xpra at %s has exited." % display_name
sys.exit(0)
elif final_state is DotXpra.UNKNOWN:
print ("How odd... I'm not sure what's going on with xpra at %s"
% display_name)
sys.exit(1)
elif final_state is DotXpra.LIVE:
print "Failed to shutdown xpra at %s" % display_name
sys.exit(1)
else:
assert False
else:
print "Sent shutdown command"
示例4: run_list
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def run_list(parser, opts, extra_args):
assert "gtk" not in sys.modules
if extra_args:
parser.error("too many arguments for mode")
sockdir = DotXpra(opts.socket_dir)
results = sockdir.sockets()
if not results:
sys.stdout.write("No xpra sessions found\n")
return 1
sys.stdout.write("Found the following xpra sessions:\n")
for state, display in results:
may_cleanup_socket(sockdir, state, display)
#now, re-probe the "unknown" ones:
unknown = [display for state, display in results if state==DotXpra.UNKNOWN]
if len(unknown)>0:
sys.stdout.write("Re-probing unknown sessions: %s\n" % (", ".join(unknown)))
counter = 0
while len(unknown)>0 and counter<5:
time.sleep(1)
counter += 1
probe_list = list(unknown)
unknown = []
for display in probe_list:
state = sockdir.server_state(display)
if state is DotXpra.DEAD:
may_cleanup_socket(sockdir, state, display)
elif state is DotXpra.UNKNOWN:
unknown.append(display)
else:
sys.stdout.write("\t%s session at %s\n" % (state, display))
#now cleanup those still unknown:
clean_states = [DotXpra.DEAD, DotXpra.UNKNOWN]
for display in unknown:
state = sockdir.server_state(display)
may_cleanup_socket(sockdir, state, display, clean_states=clean_states)
return 0
示例5: show_final_state
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def show_final_state(display):
sockdir = DotXpra(opts.sockdir)
for _ in range(6):
final_state = sockdir.server_state(display)
if final_state is DotXpra.LIVE:
time.sleep(0.5)
if final_state is DotXpra.DEAD:
print("xpra at %s has exited." % display)
return 0
elif final_state is DotXpra.UNKNOWN:
print("How odd... I'm not sure what's going on with xpra at %s" % display)
return 1
elif final_state is DotXpra.LIVE:
print("Failed to shutdown xpra at %s" % display)
return 1
else:
assert False, "invalid state: %s" % final_state
return 1
示例6: run_proxy
# 需要导入模块: from xpra.dotxpra import DotXpra [as 别名]
# 或者: from xpra.dotxpra.DotXpra import server_state [as 别名]
def run_proxy(parser, opts, script_file, args, mode):
from xpra.server.proxy import XpraProxy
assert "gtk" not in sys.modules
if mode in ("_proxy_start", "_shadow_start"):
#we must use a subprocess to avoid messing things up - yuk
cmd = [script_file]
if mode=="_proxy_start":
cmd.append("start")
assert len(args)==1, "proxy/shadow-start: expected 1 argument but got %s" % len(args)
display_name = args[0]
else:
assert mode=="_shadow_start"
cmd.append("shadow")
if len(args)==1:
#display_name was provided:
display_name = args[0]
else:
display_name = guess_X11_display()
cmd += args
if opts.start_child and len(opts.start_child)>0:
for x in opts.start_child:
cmd.append("--start-child=%s" % x)
if opts.exit_with_children:
cmd.append("--exit-with-children")
if opts.exit_with_client or mode=="_shadow_start":
cmd.append("--exit-with-client")
def setsid():
os.setsid()
Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid)
dotxpra = DotXpra()
start = time.time()
while dotxpra.server_state(display_name, 1)!=DotXpra.LIVE:
if time.time()-start>5:
warn("server failed to start after %.1f seconds - sorry!" % (time.time()-start))
return
time.sleep(0.10)
server_conn = connect_or_fail(pick_display(parser, opts, args))
app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn)
signal.signal(signal.SIGINT, app.quit)
signal.signal(signal.SIGTERM, app.quit)
app.run()
return 0