ExportXMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Normal
    • 3.0.3
    • Affects Version/s: 3.0.2
    • Component/s: Plugins API
    • None

      Adapting the example listed in Album Background Task Management (and making it actually work) with blocking=True forever blocks the album load in the UI, despite complete_album_task being called in the callback.

      Full plugin code used below (verbatim). Yes, it calls a nonexistent URL api.example.com.
      Logs (both built-in Picard and plugin logs) confirm that complete_album_task is hit.

      Notably, calling complete_album_task in the same function as the album metadata processor does mark the task as done, so it looks like there is some threading issues going on when attempting to complete a blocking request in a different QT thread (at least, print(api.tagger.thread() returned different results).

      from functools import partial
      
      from picard.plugin3.plugin import PluginApi
      
      
      def fetch_album_data(api, album, metadata, release):
          artist_id = "1234"
      
          task_id = f"bio_{album.id}"
      
          def create_request():
              return api.web_service.get_url(
                  url=f"https://api.example.com/artist/{artist_id}",
                  handler=partial(handle_response, api, album, metadata, task_id),
              )
      
          api.add_album_task(
              album,
              task_id,
              f"Fetching artist bio for {artist_id}",
              request_factory=create_request,
              blocking=True,
          )
      
      
      def handle_response(api: "PluginApi", album, metadata, task_id, data, http, error):
          try:
              if not error and data:
                  metadata["~artist_bio"] = data.get("biography", "")
          finally:
              api.complete_album_task(album, task_id)
              api.logger.info(f"Completed task: {task_id}")
      
      
      def enable(api):
          api.register_album_metadata_processor(fetch_album_data)
      

            Assignee:
            Zas
            Reporter:
            person45678
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                Version Package
                3.0.3