本文整理汇总了Python中xpra.os_util.Queue.put方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.put方法的具体用法?Python Queue.put怎么用?Python Queue.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xpra.os_util.Queue
的用法示例。
在下文中一共展示了Queue.put方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stop
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
def stop(self, reason="proxy terminating", skip_proto=None):
log.info("stop(%s, %s)", reason, skip_proto)
self.exit = True
if self.control_socket_path:
try:
os.unlink(self.control_socket_path)
except:
pass
self.control_socket_path = None
try:
self.control_socket.close()
except:
pass
self.main_queue.put(None)
#empty the main queue:
q = Queue()
q.put(None)
self.main_queue = q
#empty the encode queue:
q = Queue()
q.put(None)
self.encode_queue = q
for proto in (self.client_protocol, self.server_protocol):
if proto and proto!=skip_proto:
log("sending disconnect to %s", proto)
proto.flush_then_close(["disconnect", SERVER_SHUTDOWN, reason])
示例2: stop
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
def stop(self, reason="proxy terminating", skip_proto=None):
debug("stop(%s, %s)", reason, skip_proto)
self.main_queue.put(None)
#empty the main queue:
q = Queue()
q.put(None)
self.main_queue = q
for proto in (self.client_protocol, self.server_protocol):
if proto and proto!=skip_proto:
proto.flush_then_close(["disconnect", reason])
示例3: Invoker
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class Invoker(QtCore.QObject):
def __init__(self):
super(Invoker, self).__init__()
self.queue = Queue()
def invoke(self, func, *args):
f = lambda: func(*args)
self.queue.put(f)
QtCore.QMetaObject.invokeMethod(self, "handler", QtCore.Qt.QueuedConnection)
@QtCore.pyqtSlot()
def handler(self):
f = self.queue.get()
f()
示例4: Worker_Thread
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class Worker_Thread(Thread):
"""
A background thread which calls the functions we post to it.
The functions are placed in a queue and only called once,
when this thread gets around to it.
"""
def __init__(self):
Thread.__init__(self, name="Worker_Thread")
self.items = Queue()
self.exit = False
self.setDaemon(True)
def __repr__(self):
return "Worker_Thread(items=%s, exit=%s)" % (self.items.qsize(), self.exit)
def stop(self, force=False):
if self.exit:
return
if force:
if self.items.qsize()>0:
log.warn("Worker stop: %s items in the queue will not be run!", self.items.qsize())
self.exit = True
else:
if self.items.qsize()>0:
log.info("waiting for %s items in work queue to complete", self.items.qsize())
debug("Worker_Thread.stop(%s) %s items in work queue", force, self.items)
self.items.put(None)
def add(self, item):
if self.items.qsize()>10:
log.warn("Worker_Thread.items queue size is %s", self.items.qsize())
self.items.put(item)
def run(self):
debug("Worker_Thread.run() starting")
while not self.exit:
item = self.items.get()
if item is None:
debug("Worker_Thread.run() found end of queue marker")
self.exit = True
break
try:
debug("Worker_Thread.run() calling %s (queue size=%s)", item, self.items.qsize())
item()
except:
log.error("Error in worker thread processing item %s", item, exc_info=True)
debug("Worker_Thread.run() ended (queue size=%s)", self.items.qsize())
示例5: loopback_connection
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class loopback_connection(Connection):
""" a fake connection which just writes back whatever is sent to it """
def __init__(self, *args):
Connection.__init__(self, *args)
self.queue = Queue()
def read(self, n):
self.may_abort("read")
#FIXME: we don't handle n...
return self.queue.get(True)
def write(self, buf):
self.may_abort("write")
self.queue.put(buf)
return len(buf)
def may_abort(self, action):
return False
示例6: terminate_queue_threads
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
def terminate_queue_threads(self):
log("terminate_queue_threads()")
# the format thread will exit since closed is set too:
self._source_has_more.set()
# make the threads exit by adding the empty marker:
exit_queue = Queue()
for _ in range(10): # just 2 should be enough!
exit_queue.put(None)
try:
owq = self._write_queue
self._write_queue = exit_queue
owq.put_nowait(None)
except:
pass
try:
orq = self._read_queue
self._read_queue = exit_queue
orq.put_nowait(None)
except:
pass
示例7: Worker_Thread
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class Worker_Thread(Thread):
def __init__(self):
Thread.__init__(self, name="Worker_Thread")
self.items = Queue()
self.exit = False
self.setDaemon(True)
def stop(self, force=False):
if force:
if self.items.qsize()>0:
log.warn("Worker_Thread.stop(%s) %s items in work queue will not run!", force, self.items.qsize())
self.exit = True
else:
if self.items.qsize()>0:
log.info("waiting for %s items in work queue to complete", self.items.qsize())
debug("Worker_Thread.stop(%s) %s items in work queue: ", force, self.items)
self.items.put(None)
def add(self, item):
if self.items.qsize()>10:
log.warn("Worker_Thread.items queue size is %s", self.items.qsize())
self.items.put(item)
def run(self):
debug("Worker_Thread.run() starting")
while not self.exit:
item = self.items.get()
if item is None:
break
try:
debug("Worker_Thread.run() calling %s (queue size=%s)", item, self.items.qsize())
item()
except:
log.error("Worker_Thread.run() error on %s", item, exc_info=True)
debug("Worker_Thread.run() ended")
示例8: subprocess_callee
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class subprocess_callee(object):
"""
This is the callee side, wrapping the gobject we want to interact with.
All the input received will be converted to method calls on the wrapped object.
Subclasses should register the signal handlers they want to see exported back to the caller.
The convenience connect_export(signal-name, *args) can be used to forward signals unmodified.
You can also call send() to pass packets back to the caller.
(there is no validation of which signals are valid or not)
"""
def __init__(self, input_filename="-", output_filename="-", wrapped_object=None, method_whitelist=None):
self.name = ""
self.input_filename = input_filename
self.output_filename = output_filename
self.method_whitelist = method_whitelist
self.large_packets = []
#the gobject instance which is wrapped:
self.wrapped_object = wrapped_object
self.send_queue = Queue()
self.protocol = None
if HANDLE_SIGINT:
#this breaks gobject3!
signal.signal(signal.SIGINT, self.handle_signal)
signal.signal(signal.SIGTERM, self.handle_signal)
self.setup_mainloop()
def setup_mainloop(self):
glib = import_glib()
self.mainloop = glib.MainLoop()
self.idle_add = glib.idle_add
self.timeout_add = glib.timeout_add
self.source_remove = glib.source_remove
def connect_export(self, signal_name, *user_data):
""" gobject style signal registration for the wrapped object,
the signals will automatically be forwarded to the wrapper process
using send(signal_name, *signal_args, *user_data)
"""
log("connect_export%s", [signal_name] + list(user_data))
args = list(user_data) + [signal_name]
self.wrapped_object.connect(signal_name, self.export, *args)
def export(self, *args):
signal_name = args[-1]
log("export(%s, ...)", signal_name)
data = args[1:-1]
self.send(signal_name, *list(data))
def start(self):
self.protocol = self.make_protocol()
self.protocol.start()
try:
self.run()
return 0
except KeyboardInterrupt as e:
if str(e):
log.warn("%s", e)
return 0
except Exception:
log.error("error in main loop", exc_info=True)
return 1
finally:
self.cleanup()
if self.protocol:
self.protocol.close()
self.protocol = None
if self.input_filename=="-":
try:
self._input.close()
except:
pass
if self.output_filename=="-":
try:
self._output.close()
except:
pass
def make_protocol(self):
#figure out where we read from and write to:
if self.input_filename=="-":
#disable stdin buffering:
self._input = os.fdopen(sys.stdin.fileno(), 'rb', 0)
setbinarymode(self._input.fileno())
else:
self._input = open(self.input_filename, 'rb')
if self.output_filename=="-":
#disable stdout buffering:
self._output = os.fdopen(sys.stdout.fileno(), 'wb', 0)
setbinarymode(self._output.fileno())
else:
self._output = open(self.output_filename, 'wb')
#stdin and stdout wrapper:
conn = TwoFileConnection(self._output, self._input, abort_test=None, target=self.name, socktype=self.name, close_cb=self.net_stop)
conn.timeout = 0
protocol = Protocol(self, conn, self.process_packet, get_packet_cb=self.get_packet)
setup_fastencoder_nocompression(protocol)
protocol.large_packets = self.large_packets
return protocol
#.........这里部分代码省略.........
示例9: subprocess_caller
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
#.........这里部分代码省略.........
def fail_start(self):
raise Exception("this wrapper has already been started")
def abort_test(self, action):
p = self.process
if p is None or p.poll():
raise ConnectionClosedException("cannot %s: subprocess has terminated" % action)
def make_protocol(self):
#make a connection using the process stdin / stdout
conn = TwoFileConnection(self.process.stdin, self.process.stdout, abort_test=self.abort_test, target=self.description, socktype=self.description, close_cb=self.subprocess_exit)
conn.timeout = 0
protocol = Protocol(self, conn, self.process_packet, get_packet_cb=self.get_packet)
setup_fastencoder_nocompression(protocol)
protocol.large_packets = self.large_packets
return protocol
def exec_subprocess(self):
kwargs = exec_kwargs()
env = self.get_env()
log("exec_subprocess() command=%s, env=%s, kwargs=%s", self.command, env, kwargs)
proc = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=sys.stderr.fileno(), env=env, **kwargs)
getChildReaper().add_process(proc, self.description, self.command, True, True, callback=self.subprocess_exit)
return proc
def get_env(self):
env = exec_env()
env["XPRA_LOG_PREFIX"] = "%s " % self.description
return env
def cleanup(self):
self.stop()
def stop(self):
self.stop_process()
self.stop_protocol()
def stop_process(self):
log("%s.stop_process() sending stop request to %s", self, self.description)
proc = self.process
if proc and proc.poll() is None:
try:
proc.terminate()
self.process = None
except Exception as e:
log.warn("failed to stop the wrapped subprocess %s: %s", proc, e)
def stop_protocol(self):
p = self.protocol
if p:
self.protocol = None
log("%s.stop_protocol() calling %s", self, p.close)
try:
p.close()
except Exception as e:
log.warn("failed to close the subprocess connection: %s", p, e)
def connection_lost(self, *args):
log("connection_lost%s", args)
self.stop()
def gibberish(self, *args):
log.warn("%s stopping on gibberish:", self.description)
log.warn(" %s", repr_ellipsized(args[1], limit=80))
self.stop()
def get_packet(self):
try:
item = self.send_queue.get(False)
except:
item = None
return (item, None, None, self.send_queue.qsize()>0)
def send(self, *packet_data):
self.send_queue.put(packet_data)
p = self.protocol
if p:
p.source_has_more()
INJECT_FAULT(p)
def process_packet(self, proto, packet):
if DEBUG_WRAPPER:
log("process_packet(%s, %s)", proto, [str(x)[:32] for x in packet])
signal_name = bytestostr(packet[0])
self._fire_callback(signal_name, packet[1:])
INJECT_FAULT(proto)
def _fire_callback(self, signal_name, extra_args=[]):
callbacks = self.signal_callbacks.get(signal_name)
log("firing callback for '%s': %s", signal_name, callbacks)
if callbacks:
for cb, args in callbacks:
try:
all_args = list(args) + extra_args
self.idle_add(cb, self, *all_args)
except Exception:
log.error("error processing callback %s for %s packet", cb, signal_name, exc_info=True)
示例10: SoundSource
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
#.........这里部分代码省略.........
#info = sample.get_info()
size = buf.get_size()
extract_dup = getattr(buf, "extract_dup", None)
if extract_dup:
data = extract_dup(0, size)
else:
#crappy gi bindings detected, using workaround:
from xpra.sound.gst_hacks import map_gst_buffer
with map_gst_buffer(buf) as a:
data = bytes(a[:])
return self.emit_buffer(data, {"timestamp" : normv(buf.pts),
"duration" : normv(buf.duration),
})
def on_new_preroll0(self, appsink):
buf = appsink.emit('pull-preroll')
gstlog('new preroll0: %s bytes', len(buf))
return self.emit_buffer0(buf)
def on_new_buffer(self, bus):
#pygst 0.10
buf = self.sink.emit("pull-buffer")
return self.emit_buffer0(buf)
def caps_to_dict(self, caps):
if not caps:
return {}
d = {}
try:
for cap in caps:
name = cap.get_name()
capd = {}
for k in cap.keys():
v = cap[k]
if type(v) in (str, int):
capd[k] = cap[k]
elif k not in self.skipped_caps:
log("skipping %s cap key %s=%s of type %s", name, k, v, type(v))
d[name] = capd
except Exception as e:
log.error("Error parsing '%s':", caps)
log.error(" %s", e)
return d
def emit_buffer0(self, buf):
""" convert pygst structure into something more generic for the wire """
#none of the metadata is really needed at present, but it may be in the future:
#metadata = {"caps" : buf.get_caps().to_string(),
# "size" : buf.size,
# "timestamp" : buf.timestamp,
# "duration" : buf.duration,
# "offset" : buf.offset,
# "offset_end": buf.offset_end}
log("emit buffer: %s bytes, timestamp=%s", len(buf.data), buf.timestamp//MS_TO_NS)
metadata = {
"timestamp" : normv(buf.timestamp),
"duration" : normv(buf.duration)
}
d = self.caps_to_dict(buf.get_caps())
if not self.caps or self.caps!=d:
self.caps = d
self.info["caps"] = self.caps
metadata["caps"] = self.caps
return self.emit_buffer(buf.data, metadata)
def emit_buffer(self, data, metadata={}):
f = self.file
if f and data:
self.file.write(data)
self.file.flush()
if self.state=="stopped":
#don't bother
return 0
if JITTER>0:
#will actually emit the buffer after a random delay
if self.jitter_queue.empty():
#queue was empty, schedule a timer to flush it
from random import randint
jitter = randint(1, JITTER)
self.timeout_add(jitter, self.flush_jitter_queue)
log("emit_buffer: will flush jitter queue in %ims", jitter)
self.jitter_queue.put((data, metadata))
return 0
log("emit_buffer data=%s, len=%i, metadata=%s", type(data), len(data), metadata)
return self.do_emit_buffer(data, metadata)
def flush_jitter_queue(self):
while not self.jitter_queue.empty():
d,m = self.jitter_queue.get(False)
self.do_emit_buffer(d, m)
def do_emit_buffer(self, data, metadata={}):
self.inc_buffer_count()
self.inc_byte_count(len(data))
metadata["time"] = int(time.time()*1000)
self.idle_emit("new-buffer", data, metadata)
self.emit_info()
return 0
示例11: subprocess_caller
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
#.........这里部分代码省略.........
def exec_subprocess(self):
kwargs = self.exec_kwargs()
log("exec_subprocess() command=%s, kwargs=%s", self.command, kwargs)
proc = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=sys.stderr.fileno(), env=self.get_env(), **kwargs)
getChildReaper().add_process(proc, self.description, self.command, True, True, callback=self.subprocess_exit)
return proc
def get_env(self):
env = os.environ.copy()
env["XPRA_SKIP_UI"] = "1"
env["XPRA_LOG_PREFIX"] = "%s " % self.description
#let's make things more complicated than they should be:
#on win32, the environment can end up containing unicode, and subprocess chokes on it
for k,v in env.items():
try:
env[k] = bytestostr(v.encode("utf8"))
except:
env[k] = bytestostr(v)
return env
def exec_kwargs(self):
if os.name=="posix":
return {"close_fds" : True}
elif sys.platform.startswith("win"):
if not WIN32_SHOWWINDOW:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
return {"startupinfo" : startupinfo}
return {}
def cleanup(self):
self.stop()
def stop(self):
self.stop_process()
#call via idle_add to prevent deadlocks on win32!
gobject.idle_add(self.stop_protocol)
def stop_process(self):
log("stop() sending stop request to %s", self.description)
proc = self.process
if proc and proc.poll() is None:
try:
proc.terminate()
self.process = None
except Exception as e:
log.warn("failed to stop the wrapped subprocess %s: %s", proc, e)
def stop_protocol(self):
p = self.protocol
if p:
self.protocol = None
log("%s.stop() calling %s", self, p.close)
try:
p.close()
except Exception as e:
log.warn("failed to close the subprocess connection: %s", p, e)
def connection_lost(self, *args):
log("connection_lost%s", args)
self.stop()
def gibberish(self, *args):
log("gibberish%s", args)
self.stop()
def get_packet(self):
try:
item = self.send_queue.get(False)
except:
item = None
return (item, None, None, self.send_queue.qsize()>0)
def send(self, *packet_data):
self.send_queue.put(packet_data)
p = self.protocol
if p:
p.source_has_more()
def process_packet(self, proto, packet):
if DEBUG_WRAPPER:
log("process_packet(%s, %s)", proto, [str(x)[:32] for x in packet])
signal_name = bytestostr(packet[0])
self._fire_callback(signal_name, packet[1:])
def _fire_callback(self, signal_name, extra_args=[]):
callbacks = self.signal_callbacks.get(signal_name)
log("firing callback for %s: %s", signal_name, callbacks)
if callbacks:
for cb, args in callbacks:
try:
all_args = list(args) + extra_args
gobject.idle_add(cb, self, *all_args)
except Exception:
log.error("error processing callback %s for %s packet", cb, signal_name, exc_info=True)
示例12: ProxyInstanceProcess
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class ProxyInstanceProcess(Process):
def __init__(self, uid, gid, env_options, session_options, socket_dir,
video_encoder_modules, csc_modules,
client_conn, client_state, cipher, encryption_key, server_conn, caps, message_queue):
Process.__init__(self, name=str(client_conn))
self.uid = uid
self.gid = gid
self.env_options = env_options
self.session_options = session_options
self.socket_dir = socket_dir
self.video_encoder_modules = video_encoder_modules
self.csc_modules = csc_modules
self.client_conn = client_conn
self.client_state = client_state
self.cipher = cipher
self.encryption_key = encryption_key
self.server_conn = server_conn
self.caps = caps
log("ProxyProcess%s", (uid, gid, env_options, session_options, socket_dir,
video_encoder_modules, csc_modules,
client_conn, repr_ellipsized(str(client_state)), cipher, encryption_key, server_conn,
"%s: %s.." % (type(caps), repr_ellipsized(str(caps))), message_queue))
self.client_protocol = None
self.server_protocol = None
self.exit = False
self.main_queue = None
self.message_queue = message_queue
self.encode_queue = None #holds draw packets to encode
self.encode_thread = None
self.video_encoding_defs = None
self.video_encoders = None
self.video_encoders_last_used_time = None
self.video_encoder_types = None
self.video_helper = None
self.lost_windows = None
#for handling the local unix domain socket:
self.control_socket_cleanup = None
self.control_socket = None
self.control_socket_thread = None
self.control_socket_path = None
self.potential_protocols = []
self.max_connections = MAX_CONCURRENT_CONNECTIONS
def server_message_queue(self):
while True:
log("waiting for server message on %s", self.message_queue)
m = self.message_queue.get()
log("received proxy server message: %s", m)
if m=="stop":
self.stop("proxy server request")
return
elif m=="socket-handover-complete":
log("setting sockets to blocking mode: %s", (self.client_conn, self.server_conn))
#set sockets to blocking mode:
set_blocking(self.client_conn)
set_blocking(self.server_conn)
else:
log.error("unexpected proxy server message: %s", m)
def signal_quit(self, signum, frame):
log.info("")
log.info("proxy process pid %s got signal %s, exiting", os.getpid(), SIGNAMES.get(signum, signum))
self.exit = True
signal.signal(signal.SIGINT, deadly_signal)
signal.signal(signal.SIGTERM, deadly_signal)
self.stop(SIGNAMES.get(signum, signum))
def idle_add(self, fn, *args, **kwargs):
#we emulate gobject's idle_add using a simple queue
self.main_queue.put((fn, args, kwargs))
def timeout_add(self, timeout, fn, *args, **kwargs):
#emulate gobject's timeout_add using idle add and a Timer
#using custom functions to cancel() the timer when needed
def idle_exec():
v = fn(*args, **kwargs)
if bool(v):
self.timeout_add(timeout, fn, *args, **kwargs)
return False
def timer_exec():
#just run via idle_add:
self.idle_add(idle_exec)
Timer(timeout/1000.0, timer_exec).start()
def run(self):
log("ProxyProcess.run() pid=%s, uid=%s, gid=%s", os.getpid(), getuid(), getgid())
setuidgid(self.uid, self.gid)
if self.env_options:
#TODO: whitelist env update?
os.environ.update(self.env_options)
self.video_init()
log.info("new proxy instance started")
log.info(" for client %s", self.client_conn)
log.info(" and server %s", self.server_conn)
signal.signal(signal.SIGTERM, self.signal_quit)
signal.signal(signal.SIGINT, self.signal_quit)
log("registered signal handler %s", self.signal_quit)
#.........这里部分代码省略.........
示例13: Protocol
# 需要导入模块: from xpra.os_util import Queue [as 别名]
# 或者: from xpra.os_util.Queue import put [as 别名]
class Protocol(object):
CONNECTION_LOST = "connection-lost"
GIBBERISH = "gibberish"
INVALID = "invalid"
def __init__(self, scheduler, conn, process_packet_cb, get_packet_cb=None):
"""
You must call this constructor and source_has_more() from the main thread.
"""
assert scheduler is not None
assert conn is not None
self.timeout_add = scheduler.timeout_add
self.idle_add = scheduler.idle_add
self._conn = conn
if FAKE_JITTER > 0:
from xpra.net.fake_jitter import FakeJitter
fj = FakeJitter(self.timeout_add, process_packet_cb)
self._process_packet_cb = fj.process_packet_cb
else:
self._process_packet_cb = process_packet_cb
self._write_queue = Queue(1)
self._read_queue = Queue(20)
self._read_queue_put = self._read_queue.put
# Invariant: if .source is None, then _source_has_more == False
self._get_packet_cb = get_packet_cb
# counters:
self.input_stats = {}
self.input_packetcount = 0
self.input_raw_packetcount = 0
self.output_stats = {}
self.output_packetcount = 0
self.output_raw_packetcount = 0
# initial value which may get increased by client/server after handshake:
self.max_packet_size = 256 * 1024
self.abs_max_packet_size = 256 * 1024 * 1024
self.large_packets = ["hello"]
self.send_aliases = {}
self.receive_aliases = {}
self._log_stats = None # None here means auto-detect
self._closed = False
self.encoder = "none"
self._encoder = self.noencode
self.compressor = "none"
self._compress = compression.nocompress
self.compression_level = 0
self.cipher_in = None
self.cipher_in_name = None
self.cipher_in_block_size = 0
self.cipher_out = None
self.cipher_out_name = None
self.cipher_out_block_size = 0
self._write_lock = Lock()
from xpra.daemon_thread import make_daemon_thread
self._write_thread = make_daemon_thread(self._write_thread_loop, "write")
self._read_thread = make_daemon_thread(self._read_thread_loop, "read")
self._read_parser_thread = make_daemon_thread(self._read_parse_thread_loop, "parse")
self._write_format_thread = make_daemon_thread(self._write_format_thread_loop, "format")
self._source_has_more = threading.Event()
STATE_FIELDS = (
"max_packet_size",
"large_packets",
"send_aliases",
"receive_aliases",
"cipher_in",
"cipher_in_name",
"cipher_in_block_size",
"cipher_out",
"cipher_out_name",
"cipher_out_block_size",
"compression_level",
"encoder",
"compressor",
)
def save_state(self):
state = {}
for x in Protocol.STATE_FIELDS:
state[x] = getattr(self, x)
return state
def restore_state(self, state):
assert state is not None
for x in Protocol.STATE_FIELDS:
assert x in state, "field %s is missing" % x
setattr(self, x, state[x])
# special handling for compressor / encoder which are named objects:
self.enable_compressor(self.compressor)
self.enable_encoder(self.encoder)
def wait_for_io_threads_exit(self, timeout=None):
for t in (self._read_thread, self._write_thread):
t.join(timeout)
exited = True
for t in (self._read_thread, self._write_thread):
if t.isAlive():
log.warn("%s thread of %s has not yet exited (timeout=%s)", t.name, self._conn, timeout)
exited = False
#.........这里部分代码省略.........