<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def publish_avatar_set(self, avatar_set):
 """ Make `avatar_set` the current avatar of the jid associated with this connection. If :attr:`synchronize_vcard` is true and PEP is available the vCard is only synchronized if the PEP update is successful. This means publishing the ``image/png`` avatar data and the avatar metadata set in pubsub. The `avatar_set` must be an instance of :class:`AvatarSet`. If :attr:`synchronize_vcard` is true the avatar is additionally published in the user vCard. """

        id_ = avatar_set.png_id

        done = False
        with (yield from self._publish_lock):
            if (yield from self._pep.available()):
                yield from self._pep.publish(
                    namespaces.xep0084_data,
                    avatar_xso.Data(avatar_set.image_bytes),
                    id_=id_
                )

                yield from self._pep.publish(
                    namespaces.xep0084_metadata,
                    avatar_set.metadata,
                    id_=id_
                )
                done = True

            if self._synchronize_vcard:
                my_vcard = yield from self._vcard.get_vcard()
                my_vcard.set_photo_data("image/png",
                                        avatar_set.image_bytes)
                self._vcard_id = avatar_set.png_id
                yield from self._vcard.set_vcard(my_vcard)
                self._presence_server.resend_presence()
                done = True

        if not done:
            raise RuntimeError(
                "failed to publish avatar: no protocol available"
            )