Merge branch 'windows-subprocess-fix'

This commit is contained in:
Ellwood Zwovic
2017-08-19 19:00:52 -07:00

View File

@@ -12,11 +12,15 @@ bl_info = {
'category': 'System', 'category': 'System',
'support': 'TESTING', 'support': 'TESTING',
} }
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
if 'bpy' in locals(): try:
import bpy
except ImportError:
from . import subproc
else:
if 'bpkg' in locals():
from importlib import reload from importlib import reload
def recursive_reload(mod): def recursive_reload(mod):
@@ -35,7 +39,6 @@ if 'bpy' in locals():
bpkg = recursive_reload(bpkg) bpkg = recursive_reload(bpkg)
Package = bpkg.types.Package Package = bpkg.types.Package
else:
from . import subproc from . import subproc
from . import messages from . import messages
from . import bpkg from . import bpkg
@@ -44,10 +47,11 @@ else:
Package, Package,
ConsolidatedPackage, ConsolidatedPackage,
) )
import bpy
from pathlib import Path from pathlib import Path
from collections import OrderedDict from collections import OrderedDict
import multiprocessing
mp_context = multiprocessing.get_context('spawn')
mp_context.set_executable(bpy.app.binary_path_python)
# global list of all known packages, indexed by name # global list of all known packages, indexed by name
_packages = OrderedDict() _packages = OrderedDict()
@@ -74,8 +78,6 @@ class SubprocMixin:
self._state = 'QUIT' self._state = 'QUIT'
def invoke(self, context, event): def invoke(self, context, event):
import multiprocessing
self.pipe_blender, self.pipe_subproc = multiprocessing.Pipe() self.pipe_blender, self.pipe_subproc = multiprocessing.Pipe()
# The subprocess should just be terminated when Blender quits. Without this, # The subprocess should just be terminated when Blender quits. Without this,
@@ -135,7 +137,6 @@ class SubprocMixin:
self.pipe_blender.send(messages.Abort()) self.pipe_blender.send(messages.Abort())
def _finish(self, context): def _finish(self, context):
import multiprocessing
try: try:
self.cancel(context) self.cancel(context)
except AttributeError: except AttributeError:
@@ -213,8 +214,6 @@ class PACKAGE_OT_install(SubprocMixin, bpy.types.Operator):
:rtype: multiprocessing.Process :rtype: multiprocessing.Process
""" """
import multiprocessing
self.msg_handlers = { self.msg_handlers = {
messages.Progress: self._subproc_progress, messages.Progress: self._subproc_progress,
messages.DownloadError: self._subproc_download_error, messages.DownloadError: self._subproc_download_error,
@@ -234,7 +233,7 @@ class PACKAGE_OT_install(SubprocMixin, bpy.types.Operator):
self.log.debug("Using %s as install path", install_path) self.log.debug("Using %s as install path", install_path)
import addon_utils import addon_utils
proc = multiprocessing.Process(target=subproc.download_and_install_package, proc = mp_context.Process(target=subproc.download_and_install_package,
args=(self.pipe_subproc, package, install_path)) args=(self.pipe_subproc, package, install_path))
return proc return proc
@@ -289,8 +288,6 @@ class PACKAGE_OT_uninstall(SubprocMixin, bpy.types.Operator):
:rtype: multiprocessing.Process :rtype: multiprocessing.Process
""" """
import multiprocessing
self.msg_handlers = { self.msg_handlers = {
messages.UninstallError: self._subproc_uninstall_error, messages.UninstallError: self._subproc_uninstall_error,
messages.Success: self._subproc_success, messages.Success: self._subproc_success,
@@ -302,7 +299,7 @@ class PACKAGE_OT_uninstall(SubprocMixin, bpy.types.Operator):
global _packages global _packages
package = _packages[self.package_name].get_latest_version() package = _packages[self.package_name].get_latest_version()
proc = multiprocessing.Process(target=subproc.uninstall_package, proc = mp_context.Process(target=subproc.uninstall_package,
args=(self.pipe_subproc, package, install_path)) args=(self.pipe_subproc, package, install_path))
return proc return proc
@@ -400,8 +397,6 @@ class PACKAGE_OT_refresh(SubprocMixin, bpy.types.Operator):
:rtype: multiprocessing.Process :rtype: multiprocessing.Process
""" """
import multiprocessing
#TODO: make sure all possible messages are handled #TODO: make sure all possible messages are handled
self.msg_handlers = { self.msg_handlers = {
messages.Progress: self._subproc_progress, messages.Progress: self._subproc_progress,
@@ -419,7 +414,7 @@ class PACKAGE_OT_refresh(SubprocMixin, bpy.types.Operator):
repository_urls = [repo.url for repo in self.repositories] repository_urls = [repo.url for repo in self.repositories]
self.log.debug("Repository urls %s", repository_urls) self.log.debug("Repository urls %s", repository_urls)
proc = multiprocessing.Process(target=subproc.refresh_repositories, proc = mp_context.Process(target=subproc.refresh_repositories,
args=(self.pipe_subproc, storage_path, repository_urls)) args=(self.pipe_subproc, storage_path, repository_urls))
return proc return proc