本文整理汇总了Python中xpra.os_util.Queue类的典型用法代码示例。如果您正苦于以下问题:Python Queue类的具体用法?Python Queue怎么用?Python Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
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)
start_thread(self.server_message_queue, "server message queue")
if not self.create_control_socket():
#TODO: should send a message to the client
return
self.control_socket_thread = start_thread(self.control_socket_loop, "control")
self.main_queue = Queue()
#setup protocol wrappers:
self.server_packets = Queue(PROXY_QUEUE_SIZE)
self.client_packets = Queue(PROXY_QUEUE_SIZE)
self.client_protocol = Protocol(self, self.client_conn, self.process_client_packet, self.get_client_packet)
self.client_protocol.restore_state(self.client_state)
self.server_protocol = Protocol(self, self.server_conn, self.process_server_packet, self.get_server_packet)
#server connection tweaks:
self.server_protocol.large_packets.append("draw")
self.server_protocol.large_packets.append("window-icon")
self.server_protocol.large_packets.append("keymap-changed")
self.server_protocol.large_packets.append("server-settings")
if self.caps.boolget("file-transfer"):
self.client_protocol.large_packets.append("send-file")
self.client_protocol.large_packets.append("send-file-chunk")
self.server_protocol.large_packets.append("send-file")
self.server_protocol.large_packets.append("send-file-chunk")
self.server_protocol.set_compression_level(self.session_options.get("compression_level", 0))
self.server_protocol.enable_default_encoder()
self.lost_windows = set()
self.encode_queue = Queue()
self.encode_thread = start_thread(self.encode_loop, "encode")
log("starting network threads")
self.server_protocol.start()
self.client_protocol.start()
self.send_hello()
self.timeout_add(VIDEO_TIMEOUT*1000, self.timeout_video_encoders)
try:
self.run_queue()
except KeyboardInterrupt as e:
self.stop(str(e))
finally:
log("ProxyProcess.run() ending %s", os.getpid())
开发者ID:svn2github,项目名称:Xpra,代码行数:60,代码来源:proxy_instance_process.py
示例2: stop
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])
开发者ID:Brainiarc7,项目名称:xpra,代码行数:10,代码来源:proxy_instance_process.py
示例3: __init__
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()
开发者ID:svn2github,项目名称:Xpra,代码行数:55,代码来源:protocol.py
示例4: start_tcp_proxy
def start_tcp_proxy(self, proto, data):
proxylog("start_tcp_proxy(%s, '%s')", proto, repr_ellipsized(data))
try:
self._potential_protocols.remove(proto)
except:
pass # might already have been removed by now
proxylog("start_tcp_proxy: protocol state before stealing: %s", proto.get_info(alias_info=False))
# any buffers read after we steal the connection will be placed in this temporary queue:
temp_read_buffer = Queue()
client_connection = proto.steal_connection(temp_read_buffer.put)
# connect to web server:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
host, port = self._tcp_proxy.split(":", 1)
try:
web_server_connection = _socket_connect(sock, (host, int(port)), "web-proxy-for-%s" % proto, "tcp")
except:
proxylog.warn("failed to connect to proxy: %s:%s", host, port)
proto.gibberish("invalid packet header", data)
return
proxylog("proxy connected to tcp server at %s:%s : %s", host, port, web_server_connection)
sock.settimeout(self._socket_timeout)
ioe = proto.wait_for_io_threads_exit(0.5 + self._socket_timeout)
if not ioe:
proxylog.warn("proxy failed to stop all existing network threads!")
self.disconnect_protocol(proto, "internal threading error")
return
# now that we own it, we can start it again:
client_connection.set_active(True)
# and we can use blocking sockets:
self.set_socket_timeout(client_connection, None)
# prevent deadlocks on exit:
sock.settimeout(1)
proxylog("pushing initial buffer to its new destination: %s", repr_ellipsized(data))
web_server_connection.write(data)
while not temp_read_buffer.empty():
buf = temp_read_buffer.get()
if buf:
proxylog("pushing read buffer to its new destination: %s", repr_ellipsized(buf))
web_server_connection.write(buf)
p = XpraProxy(client_connection.target, client_connection, web_server_connection)
self._tcp_proxy_clients.append(p)
proxylog.info(
"client connection from %s forwarded to proxy server on %s:%s", client_connection.target, host, port
)
p.run()
proxylog("run_proxy() %s ended", p)
if p in self._tcp_proxy_clients:
self._tcp_proxy_clients.remove(p)
开发者ID:svn2github,项目名称:Xpra,代码行数:51,代码来源:server_core.py
示例5: Invoker
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()
开发者ID:Brainiarc7,项目名称:xpra,代码行数:14,代码来源:scheduler.py
示例6: loopback_connection
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
开发者ID:svn2github,项目名称:Xpra,代码行数:18,代码来源:subprocess_wrapper_test.py
示例7: terminate_queue_threads
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
开发者ID:svn2github,项目名称:Xpra,代码行数:20,代码来源:protocol.py
示例8: __init__
def __init__(self, description="wrapper"):
self.process = None
self.protocol = None
self.command = None
self.description = description
self.send_queue = Queue()
self.signal_callbacks = {}
self.large_packets = []
#hook a default packet handlers:
self.connect(Protocol.CONNECTION_LOST, self.connection_lost)
self.connect(Protocol.GIBBERISH, self.gibberish)
开发者ID:svn2github,项目名称:Xpra,代码行数:11,代码来源:subprocess_wrapper.py
示例9: stop
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])
开发者ID:svn2github,项目名称:Xpra,代码行数:26,代码来源:proxy_instance_process.py
示例10: stop
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.items.put(None)
self.items = Queue()
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)
开发者ID:svn2github,项目名称:Xpra,代码行数:14,代码来源:background_worker.py
示例11: __init__
def __init__(self, description="wrapper"):
self.process = None
self.protocol = None
self.command = None
self.description = description
self.send_queue = Queue()
self.signal_callbacks = {}
self.large_packets = []
#hook a default packet handlers:
self.connect(Protocol.CONNECTION_LOST, self.connection_lost)
self.connect(Protocol.GIBBERISH, self.gibberish)
glib = import_glib()
self.idle_add = glib.idle_add
self.timeout_add = glib.timeout_add
self.source_remove = glib.source_remove
开发者ID:svn2github,项目名称:Xpra,代码行数:15,代码来源:subprocess_wrapper.py
示例12: subprocess_caller
class subprocess_caller(object):
"""
This is the caller side, wrapping the subprocess.
You can call send() to pass packets to it
which will get converted to method calls on the receiving end,
You can register for signals, in which case your callbacks will be called
when those signals are forwarded back.
(there is no validation of which signals are valid or not)
"""
def __init__(self, description="wrapper"):
self.process = None
self.protocol = None
self.command = None
self.description = description
self.send_queue = Queue()
self.signal_callbacks = {}
self.large_packets = []
#hook a default packet handlers:
self.connect(Protocol.CONNECTION_LOST, self.connection_lost)
self.connect(Protocol.GIBBERISH, self.gibberish)
glib = import_glib()
self.idle_add = glib.idle_add
self.timeout_add = glib.timeout_add
self.source_remove = glib.source_remove
def connect(self, signal, cb, *args):
""" gobject style signal registration """
self.signal_callbacks.setdefault(signal, []).append((cb, list(args)))
def subprocess_exit(self, *args):
#beware: this may fire more than once!
log("subprocess_exit%s command=%s", args, self.command)
self._fire_callback("exit")
def start(self):
self.start = self.fail_start
self.process = self.exec_subprocess()
self.protocol = self.make_protocol()
self.protocol.start()
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)
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:101,代码来源:subprocess_wrapper.py
示例13: __init__
def __init__(self, src_type=None, src_options={}, codecs=get_codecs(), codec_options={}, volume=1.0):
if not src_type:
try:
from xpra.sound.pulseaudio.pulseaudio_util import get_pa_device_options
monitor_devices = get_pa_device_options(True, False)
log.info("found pulseaudio monitor devices: %s", monitor_devices)
except ImportError as e:
log.warn("Warning: pulseaudio is not available!")
log.warn(" %s", e)
monitor_devices = []
if len(monitor_devices)==0:
log.warn("could not detect any pulseaudio monitor devices")
log.warn(" a test source will be used instead")
src_type = "audiotestsrc"
default_src_options = {"wave":2, "freq":100, "volume":0.4}
else:
monitor_device = monitor_devices.items()[0][0]
log.info("using pulseaudio source device:")
log.info(" '%s'", monitor_device)
src_type = "pulsesrc"
default_src_options = {"device" : monitor_device}
src_options = default_src_options
if src_type not in get_source_plugins():
raise InitExit(1, "invalid source plugin '%s', valid options are: %s" % (src_type, ",".join(get_source_plugins())))
matching = [x for x in CODEC_ORDER if (x in codecs and x in get_codecs())]
log("SoundSource(..) found matching codecs %s", matching)
if not matching:
raise InitExit(1, "no matching codecs between arguments '%s' and supported list '%s'" % (csv(codecs), csv(get_codecs().keys())))
codec = matching[0]
encoder, fmt = get_encoder_formatter(codec)
self.queue = None
self.caps = None
self.volume = None
self.sink = None
self.src = None
self.src_type = src_type
self.buffer_latency = False
self.jitter_queue = None
self.file = None
SoundPipeline.__init__(self, codec)
src_options["name"] = "src"
source_str = plugin_str(src_type, src_options)
#FIXME: this is ugly and relies on the fact that we don't pass any codec options to work!
encoder_str = plugin_str(encoder, codec_options or get_encoder_default_options(encoder))
fmt_str = plugin_str(fmt, MUXER_DEFAULT_OPTIONS.get(fmt, {}))
pipeline_els = [source_str]
if SOURCE_QUEUE_TIME>0:
queue_el = ["queue",
"name=queue",
"min-threshold-time=0",
"max-size-buffers=0",
"max-size-bytes=0",
"max-size-time=%s" % (SOURCE_QUEUE_TIME*MS_TO_NS),
"leaky=%s" % GST_QUEUE_LEAK_DOWNSTREAM]
pipeline_els += [" ".join(queue_el)]
if encoder in ENCODER_NEEDS_AUDIOCONVERT or src_type in SOURCE_NEEDS_AUDIOCONVERT:
pipeline_els += ["audioconvert"]
pipeline_els.append("volume name=volume volume=%s" % volume)
pipeline_els += [encoder_str,
fmt_str,
APPSINK]
if not self.setup_pipeline_and_bus(pipeline_els):
return
self.volume = self.pipeline.get_by_name("volume")
self.sink = self.pipeline.get_by_name("sink")
if SOURCE_QUEUE_TIME>0:
self.queue = self.pipeline.get_by_name("queue")
if self.queue:
try:
self.queue.set_property("silent", True)
except Exception as e:
log("cannot make queue silent: %s", e)
try:
if get_gst_version()<(1,0):
self.sink.set_property("enable-last-buffer", False)
else:
self.sink.set_property("enable-last-sample", False)
except Exception as e:
log("failed to disable last buffer: %s", e)
self.skipped_caps = set()
if JITTER>0:
self.jitter_queue = Queue()
try:
#Gst 1.0:
self.sink.connect("new-sample", self.on_new_sample)
self.sink.connect("new-preroll", self.on_new_preroll1)
except:
#Gst 0.10:
self.sink.connect("new-buffer", self.on_new_buffer)
self.sink.connect("new-preroll", self.on_new_preroll0)
self.src = self.pipeline.get_by_name("src")
try:
for x in ("actual-buffer-time", "actual-latency-time"):
#don't comment this out, it is used to verify the attributes are present:
gstlog("initial %s: %s", x, self.src.get_property(x))
self.buffer_latency = True
except Exception as e:
log.info("source %s does not support 'buffer-time' or 'latency-time':", self.src_type)
log.info(" %s", e)
else:
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:101,代码来源:src.py
示例14: SoundSource
class SoundSource(SoundPipeline):
__gsignals__ = SoundPipeline.__generic_signals__.copy()
__gsignals__.update({
"new-buffer" : n_arg_signal(2),
})
def __init__(self, src_type=None, src_options={}, codecs=get_codecs(), codec_options={}, volume=1.0):
if not src_type:
try:
from xpra.sound.pulseaudio.pulseaudio_util import get_pa_device_options
monitor_devices = get_pa_device_options(True, False)
log.info("found pulseaudio monitor devices: %s", monitor_devices)
except ImportError as e:
log.warn("Warning: pulseaudio is not available!")
log.warn(" %s", e)
monitor_devices = []
if len(monitor_devices)==0:
log.warn("could not detect any pulseaudio monitor devices")
log.warn(" a test source will be used instead")
src_type = "audiotestsrc"
default_src_options = {"wave":2, "freq":100, "volume":0.4}
else:
monitor_device = monitor_devices.items()[0][0]
log.info("using pulseaudio source device:")
log.info(" '%s'", monitor_device)
src_type = "pulsesrc"
default_src_options = {"device" : monitor_device}
src_options = default_src_options
if src_type not in get_source_plugins():
raise InitExit(1, "invalid source plugin '%s', valid options are: %s" % (src_type, ",".join(get_source_plugins())))
matching = [x for x in CODEC_ORDER if (x in codecs and x in get_codecs())]
log("SoundSource(..) found matching codecs %s", matching)
if not matching:
raise InitExit(1, "no matching codecs between arguments '%s' and supported list '%s'" % (csv(codecs), csv(get_codecs().keys())))
codec = matching[0]
encoder, fmt = get_encoder_formatter(codec)
self.queue = None
self.caps = None
self.volume = None
self.sink = None
self.src = None
self.src_type = src_type
self.buffer_latency = False
self.jitter_queue = None
self.file = None
SoundPipeline.__init__(self, codec)
src_options["name"] = "src"
source_str = plugin_str(src_type, src_options)
#FIXME: this is ugly and relies on the fact that we don't pass any codec options to work!
encoder_str = plugin_str(encoder, codec_options or get_encoder_default_options(encoder))
fmt_str = plugin_str(fmt, MUXER_DEFAULT_OPTIONS.get(fmt, {}))
pipeline_els = [source_str]
if SOURCE_QUEUE_TIME>0:
queue_el = ["queue",
"name=queue",
"min-threshold-time=0",
"max-size-buffers=0",
"max-size-bytes=0",
"max-size-time=%s" % (SOURCE_QUEUE_TIME*MS_TO_NS),
"leaky=%s" % GST_QUEUE_LEAK_DOWNSTREAM]
pipeline_els += [" ".join(queue_el)]
if encoder in ENCODER_NEEDS_AUDIOCONVERT or src_type in SOURCE_NEEDS_AUDIOCONVERT:
pipeline_els += ["audioconvert"]
pipeline_els.append("volume name=volume volume=%s" % volume)
pipeline_els += [encoder_str,
fmt_str,
APPSINK]
if not self.setup_pipeline_and_bus(pipeline_els):
return
self.volume = self.pipeline.get_by_name("volume")
self.sink = self.pipeline.get_by_name("sink")
if SOURCE_QUEUE_TIME>0:
self.queue = self.pipeline.get_by_name("queue")
if self.queue:
try:
self.queue.set_property("silent", True)
except Exception as e:
log("cannot make queue silent: %s", e)
try:
if get_gst_version()<(1,0):
self.sink.set_property("enable-last-buffer", False)
else:
self.sink.set_property("enable-last-sample", False)
except Exception as e:
log("failed to disable last buffer: %s", e)
self.skipped_caps = set()
if JITTER>0:
self.jitter_queue = Queue()
try:
#Gst 1.0:
self.sink.connect("new-sample", self.on_new_sample)
self.sink.connect("new-preroll", self.on_new_preroll1)
except:
#Gst 0.10:
self.sink.connect("new-buffer", self.on_new_buffer)
self.sink.connect("new-preroll", self.on_new_preroll0)
self.src = self.pipeline.get_by_name("src")
try:
for x in ("actual-buffer-time", "actual-latency-time"):
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:101,代码来源:src.py
示例15: __init__
def __init__(self, *args):
Connection.__init__(self, *args)
self.queue = Queue()
开发者ID:svn2github,项目名称:Xpra,代码行数:3,代码来源:subprocess_wrapper_test.py
示例16: __init__
def __init__(self):
Thread.__init__(self, name="Worker_Thread")
self.items = Queue()
self.exit = False
self.setDaemon(True)
开发者ID:Brainiarc7,项目名称:xpra,代码行数:5,代码来源:background_worker.py
示例17: Worker_Thread
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")
开发者ID:Brainiarc7,项目名称:xpra,代码行数:36,代码来源:background_worker.py
示例18: __init__
def __init__(self):
super(Invoker, self).__init__()
self.queue = Queue()
开发者ID:Brainiarc7,项目名称:xpra,代码行数:3,代码来源:scheduler.py
示例19: run
def run(self):
log("ProxyProcess.run() pid=%s, uid=%s, gid=%s", os.getpid(), os.getuid(), os.getgid())
#change uid and gid:
if os.getgid()!=self.gid:
os.setgid(self.gid)
if os.getuid()!=self.uid:
os.setuid(self.uid)
log("ProxyProcess.run() new uid=%s, gid=%s", os.getuid(), os.getgid())
if self.env_options:
#TODO: whitelist env update?
os.environ.update(self.env_options)
self.video_init()
log.info("new proxy started for client %s and server %s", self.client_conn, 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)
make_daemon_thread(self.server_message_queue, "server message queue").start()
if self.create_control_socket():
self.control_socket_thread = make_daemon_thread(self.control_socket_loop, "control")
self.control_socket_thread.start()
self.main_queue = Queue()
#setup protocol wrappers:
self.server_packets = Queue(PROXY_QUEUE_SIZE)
self.client_packets = Queue(PROXY_QUEUE_SIZE)
self.client_protocol = Protocol(self, self.client_conn, self.process_client_packet, self.get_client_packet)
self.client_protocol.restore_state(self.client_state)
self.server_protocol = Protocol(self, self.server_conn, self.process_server_packet, self.get_server_packet)
#server connection tweaks:
self.server_protocol.large_packets.append("draw")
self.server_protocol.large_packets.append("window-icon")
self.server_protocol.large_packets.append("keymap-changed")
self.server_protocol.large_packets.append("server-settings")
self.server_protocol.set_compression_level(self.session_options.get("compression_level", 0))
self.server_protocol.enable_default_encoder()
self.lost_windows = set()
self.encode_queue = Queue()
self.encode_thread = make_daemon_thread(self.encode_loop, "encode")
self.encode_thread.start()
log("starting network threads")
self.server_protocol.start()
self.client_protocol.start()
#forward the hello packet:
hello_packet = ("hello", self.filter_client_caps(self.caps))
self.queue_server_packet(hello_packet)
self.timeout_add(VIDEO_TIMEOUT*1000, self.timeout_video_encoders)
try:
try:
self.run_queue()
except KeyboardInterrupt as e:
self.stop(str(e))
finally:
log("ProxyProcess.run() ending %s", os.getpid())
开发者ID:svn2github,项目名称:Xpra,代码行数:62,代码来源:proxy_instance_process.py
示例20: subprocess_caller
class subprocess_caller(object):
"""
This is the caller side, wrapping the subprocess.
You can call send() to pass packets to it
which will get converted to method calls on the receiving end,
You can register for signals, in which case your callbacks will be called
when those signals are forwarded back.
(there is no validation of which signals are valid or not)
"""
def __init__(self, description="wrapper"):
self.process = None
self.protocol = None
self.command = None
self.description = description
self.send_queue = Queue()
self.signal_callbacks = {}
self.large_packets = []
#hook a default packet handlers:
self.connect(Protocol.CONNECTION_LOST, self.connection_lost)
self.connect(Protocol.GIBBERISH, self.gibberish)
def connect(self, signal, cb, *args):
""" gobject style signal registration """
self.signal_callbacks.setdefault(signal, []).append((cb, list(args)))
def subprocess_exit(self, *args):
#beware: this may fire more than once!
log("subprocess_exit%s command=%s", args, self.command)
self._fire_callback("exit")
def start(self):
self.process = self.exec_subprocess()
self.protocol = self.make_protocol()
self.protocol.start()
def make_protocol(self):
#make a connection using the process stdin / stdout
conn = TwoFileConnection(self.process.stdin, self.process.stdout, abort_test=None, target=self.description, info=self.description, close_cb=self.subprocess_exit)
conn.timeout = 0
protocol = Protocol(gobject, conn, self.process_packet, get_packet_cb=self.get_packet)
#we assume the other end has the same encoders (which is reasonable):
#TODO: fallback to bencoder
try:
protocol.enable_encoder("rencode")
except Exception as e:
log.warn("failed to enable rencode: %s", e)
protocol.enable_encoder("bencode")
#we assume this is local, so no compression:
protocol.enable_compressor("none")
protocol.large_packets = self.large_packets
return protocol
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:
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:101,代码来源:subprocess_wrapper.py
注:本文中的xpra.os_util.Queue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论