def listen(self, callback, *args, **kwargs):
if self.lock is None:<EOL><INDENT>self.lock = Lock()<EOL><DEDENT>with self.lock:<EOL><INDENT>if self.is_connected(callback):<EOL><INDENT>raise AttributeError('<STR_LIT>')<EOL><DEDENT>if self.weak_subscribers is None:<EOL><INDENT>self.weak_subscribers = []<EOL><DEDENT>ref = weakmethod.ref(callback, self._try_disconnect)<EOL>self.weak_subscribers.append((ref, args, kwargs))<EOL><DEDENT>return ref<EOL>
Like :class:`connect()`, but uses a weak reference instead of a
normal reference.
The signal is automatically disconnected as soon as the handler
is garbage collected.

.. note::

    Storing signal handlers as weak references means that if
    your handler is a local function, it may be garbage collected. To
    prevent this, use :class:`connect()` instead.

:type  callback: object
:param callback: The callback function.
:type  args: tuple
:param args: Optional arguments passed to the callback.
:type  kwargs: dict
:param kwargs: Optional keyword arguments passed to the callback.
:rtype:  :class:`Exscript.util.weakmethod.WeakMethod`
:returns: The newly created weak reference to the callback.