Get print() working in fetch worker

This commit is contained in:
Kovid Goyal 2024-08-09 19:33:55 +05:30
parent 339ec662d4
commit 408193c895
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -17,10 +17,6 @@ from calibre.scraper.simple_backend import create_base_profile
default_timeout: float = 60. # seconds default_timeout: float = 60. # seconds
def debug(*a, **kw):
print(*a, **kw, file=sys.stderr)
class RequestInterceptor(QWebEngineUrlRequestInterceptor): class RequestInterceptor(QWebEngineUrlRequestInterceptor):
def interceptRequest(self, req: QWebEngineUrlRequestInfo) -> None: def interceptRequest(self, req: QWebEngineUrlRequestInfo) -> None:
@ -218,7 +214,7 @@ class FetchBackend(QWebEnginePage):
def send_response(self, r: dict[str, str]) -> None: def send_response(self, r: dict[str, str]) -> None:
with suppress(OSError): with suppress(OSError):
print(json.dumps(r), flush=True) print(json.dumps(r), flush=True, file=sys.__stdout__)
def set_user_agent(self, new_val: str) -> None: def set_user_agent(self, new_val: str) -> None:
self.profile().setHttpUserAgent(new_val) self.profile().setHttpUserAgent(new_val)
@ -277,6 +273,7 @@ def read_commands(backend: FetchBackend, tdir: str) -> None:
def worker(tdir: str, user_agent: str) -> None: def worker(tdir: str, user_agent: str) -> None:
app = QApplication.instance() app = QApplication.instance()
sys.stdout = sys.stderr
backend = FetchBackend(output_dir=tdir, parent=app, user_agent=user_agent) backend = FetchBackend(output_dir=tdir, parent=app, user_agent=user_agent)
try: try:
read_thread = Thread(target=read_commands, args=(backend, tdir), daemon=True) read_thread = Thread(target=read_commands, args=(backend, tdir), daemon=True)