def run_calibre_debug(*args, **kw): import subprocess creationflags = 0 if iswindows: creationflags = subprocess.CREATE_NO_WINDOW cmd = get_debug_executable() + list(args) kw['creationflags'] = creationflags return subprocess.Popen(cmd, **kw)
def send_message_via_worker(msg, address=None, timeout=5, wait_till_sent=False): # On Windows sending a message in a process that also is listening on the # same named pipe in a different thread deadlocks, so we do the actual sending in # a simple worker process import json import subprocess from calibre.startup import get_debug_executable cmd = get_debug_executable() + [ '-c', 'from calibre.gui2.listener import *; import sys, json;' 'send_message_implementation(sys.stdin.buffer.read(), address=json.loads(sys.argv[-2]), timeout=int(sys.argv[-1]))', json.dumps(address), str(timeout)] p = subprocess.Popen(cmd, stdin=subprocess.PIPE) if isinstance(msg, str): msg = msg.encode('utf-8') with closing(p.stdin): p.stdin.write(msg) if wait_till_sent: return p.wait(timeout=timeout) == 0