Skip to content

Commit

Permalink
Change: Pyblish Wait for pool futures to finish (#84)
Browse files Browse the repository at this point in the history
* Change: Pyblish Wait for pool futures to finish

* change futures key name

* black
  • Loading branch information
Tilix4 committed Mar 24, 2023
1 parent 2559c8d commit b863292
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 17 additions & 7 deletions openpype/hosts/blender/plugins/publish/integrate_blend.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def process(self, instance):
representations.update(instance.data.get("hero_representations", {}))

# Run commands for all published representations
instance.data.setdefault("representations_futures", [])
for representation in representations.values():
representation = representation["representation"]
published_path = representation.get("data", {}).get("path")
Expand All @@ -66,17 +67,19 @@ def process(self, instance):
sync_server_module.pause_representation(
project_name, repre_id, site
)

if use_path_management:
self.log.info(
f"Running {make_paths_relative.__file__}"
f"to {published_path}..."
)
# Make paths relative
main_command.extend([
"-P",
make_paths_relative.__file__,
])
main_command.extend(
[
"-P",
make_paths_relative.__file__,
]
)

self.log.info(
f"Running {update_representations.__file__}"
Expand All @@ -100,7 +103,9 @@ def process(self, instance):
str(repre_id),
]
)
main_command.extend(["--published_time", instance.context.data["time"]])
main_command.extend(
["--published_time", instance.context.data["time"]]
)

# Build function to callback
def callback(id: ObjectId, future: Future):
Expand All @@ -112,8 +117,13 @@ def callback(id: ObjectId, future: Future):
)

# Submit command to pool
f = pool.submit(subprocess.check_call, main_command, shell=False)
f = pool.submit(
subprocess.check_call, main_command, shell=False
)
f.add_done_callback(partial(callback, repre_id))

# Keep future for waiting for it to finish at unpause
instance.data["representations_futures"].append(f)

# Go asynchrone
pool.shutdown(wait=False)
8 changes: 8 additions & 0 deletions openpype/hosts/blender/plugins/publish/unpause_sync_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
import pyblish

from openpype.modules.base import ModulesManager
Expand All @@ -15,3 +16,10 @@ def process(self, context):
manager = ModulesManager()
sync_server_module = manager.modules_by_name["sync_server"]
sync_server_module.unpause_server()

# Wait for all started futures to finish
for instance in context:
for future in instance.data.get("representations_futures", []):
while future.running():
self.log.debug(f"Waiting for {future} to finish...")
sleep(1)

0 comments on commit b863292

Please sign in to comment.