Connects a new callback to this signal.

        :param callback: The callback to connect.
        :param weak: If `True`, only holds a weak reference to the specified
            callback.

        `callback` will be called whenever `emit` gets called on the `Signal`
        instance.

        If a weak reference is kept, when the callback gets destroyed, it will
        be unregistered from the signal automatically. This can help avoiding
        circular references in user-code.

        .. warning::
            Beware of bound methods ! Those are generally short-lived and don't
            play nicely with weak reference.

        .. note::
            Connecting the same callback twice or more will cause the callback
            to be called several times per `emit` call.

            You will have to call `disconnect` as many times as the `connect`
            call was called to unregister a callback completely.

def connect(self, callback, weak=False):
        """
        Connects a new callback to this signal.

        :param callback: The callback to connect.
        :param weak: If `True`, only holds a weak reference to the specified
            callback.

        `callback` will be called whenever `emit` gets called on the `Signal`
        instance.

        If a weak reference is kept, when the callback gets destroyed, it will
        be unregistered from the signal automatically. This can help avoiding
        circular references in user-code.

        .. warning::
            Beware of bound methods ! Those are generally short-lived and don't
            play nicely with weak reference.

        .. note::
            Connecting the same callback twice or more will cause the callback
            to be called several times per `emit` call.

            You will have to call `disconnect` as many times as the `connect`
            call was called to unregister a callback completely.
        """
        if weak:
            callback = ref(callback, self._disconnect)

        with self._write_lock:
            with self._read_lock:
                self._callbacks.append(callback)