Skip to content

Commit

Permalink
Do not use lambda to declare signal callbacks
Browse files Browse the repository at this point in the history
As written at [1], this might be a cause for the segfaults observed at
interpreter shutdown time.

[1] http://enki-editor.org/2014/08/23/Pyqt_mem_mgmt.html
  • Loading branch information
EvaSDK committed Dec 28, 2016
1 parent d444752 commit 3aefe85
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ghost/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import subprocess
import re
from functools import wraps
from functools import partial, wraps
try:
from cookielib import Cookie, LWPCookieJar
except ImportError:
Expand Down Expand Up @@ -235,6 +235,12 @@ def reply_ready_read(reply):
reply.readAll()


def reply_download_progress(reply, received, total):
"""Log `reply` download progress."""
reply.manager().logger.debug('Downloading content of %s: %s of %s',
reply.url().toString(), received, total)


class NetworkAccessManager(QNetworkAccessManager):
"""Subclass QNetworkAccessManager to always cache the reply content
Expand All @@ -248,8 +254,7 @@ def __init__(self, exclude_regex=None, logger=None, *args, **kwargs):

# Keep a registry of in-flight requests
self._registry = {}
self.finished.connect(lambda reply:
self._reply_finished_callback(reply))
self.finished.connect(self._reply_finished_callback)

def createRequest(self, operation, request, data):
"""Create a new QNetworkReply."""
Expand All @@ -266,12 +271,9 @@ def createRequest(self, operation, request, data):
request,
data
)
reply.readyRead.connect(lambda reply=reply: reply_ready_peek(reply))

reply.readyRead.connect(partial(reply_ready_peek, reply))
reply.downloadProgress.connect(
lambda received, total:
self.logger.debug('Downloading content of %s: %s of %s',
reply.url(), received, total)
partial(reply_download_progress, reply)
)

self.logger.debug('Registring reply for %s', reply.url())
Expand Down

0 comments on commit 3aefe85

Please sign in to comment.