mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 11:09:56 +00:00
Break reference cycle to fix potential memory leaks for callback handlers.
This commit is contained in:
parent
ccbef6b696
commit
335dc2927b
3 changed files with 10 additions and 4 deletions
|
@ -6,6 +6,8 @@
|
||||||
See the file LICENSE for copying permission.
|
See the file LICENSE for copying permission.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import weakref
|
||||||
|
|
||||||
|
|
||||||
class BaseHandler(object):
|
class BaseHandler(object):
|
||||||
|
|
||||||
|
@ -43,7 +45,10 @@ class BaseHandler(object):
|
||||||
stream -- The XMLStream instance the handler should monitor.
|
stream -- The XMLStream instance the handler should monitor.
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.stream = stream
|
if stream is not None:
|
||||||
|
self.stream = weakref.ref(stream)
|
||||||
|
else:
|
||||||
|
self.stream = None
|
||||||
self._destroy = False
|
self._destroy = False
|
||||||
self._payload = None
|
self._payload = None
|
||||||
self._matcher = matcher
|
self._matcher = matcher
|
||||||
|
|
|
@ -85,14 +85,14 @@ class Waiter(BaseHandler):
|
||||||
value sleekxmpp.xmlstream.RESPONSE_TIMEOUT.
|
value sleekxmpp.xmlstream.RESPONSE_TIMEOUT.
|
||||||
"""
|
"""
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = self.stream.response_timeout
|
timeout = self.stream().response_timeout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stanza = self._payload.get(True, timeout)
|
stanza = self._payload.get(True, timeout)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
stanza = False
|
stanza = False
|
||||||
log.warning("Timed out waiting for %s" % self.name)
|
log.warning("Timed out waiting for %s" % self.name)
|
||||||
self.stream.removeHandler(self.name)
|
self.stream().remove_handler(self.name)
|
||||||
return stanza
|
return stanza
|
||||||
|
|
||||||
def check_delete(self):
|
def check_delete(self):
|
||||||
|
|
|
@ -19,6 +19,7 @@ import threading
|
||||||
import time
|
import time
|
||||||
import types
|
import types
|
||||||
import random
|
import random
|
||||||
|
import weakref
|
||||||
try:
|
try:
|
||||||
import queue
|
import queue
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -719,7 +720,7 @@ class XMLStream(object):
|
||||||
"""
|
"""
|
||||||
if handler.stream is None:
|
if handler.stream is None:
|
||||||
self.__handlers.append(handler)
|
self.__handlers.append(handler)
|
||||||
handler.stream = self
|
handler.stream = weakref.ref(self)
|
||||||
|
|
||||||
def remove_handler(self, name):
|
def remove_handler(self, name):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue