Commit 238521df authored by Jørgen Lind's avatar Jørgen Lind
Browse files

Merge branch feature/jorgen.lind/python_cleanup_request with refs/heads/master...

Merge branch feature/jorgen.lind/python_cleanup_request with refs/heads/master into refs/merge-requests/214/train
parents 50e1b9c9 3a52da1e
Pipeline #6505 passed with stages
in 5 minutes and 26 seconds
......@@ -49,9 +49,9 @@ SET(pythonsources
${CMAKE_CURRENT_SOURCE_DIR}/volumedataaccessors.py
)
add_custom_command(TARGET core
POST_BUILD
add_custom_target(core_py_files ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${pythonsources} $<TARGET_FILE_DIR:core>)
#add_dependencies(core core_py_files)
copyDllForTarget(core)
setWarningFlagsForTarget(core)
......
import openvds.core
import numpy as np
import weakref
from openvds.core import VolumeDataLayout, VolumeDataPageAccessor
from .volumedataaccessors import VolmeDataAccessorManager
......@@ -47,7 +49,15 @@ def _ndarrayarray(tuples: List[Tuple[float]]):
for i in range(l):
arr[i][:len(tuples[i])] = tuples[i]
return arr
def _finalizeVolumeDataRequest(volumeDataRequest):
if not volumeDataRequest.isCompleted:
volumeDataRequest._accessManager.cancel(volumeDataRequest.requestID)
volumeDataRequest._accessManager.waitForCompletion(volumeDataRequest.requestID, 0)
volumeDataRequest._accessManager.isCanceled(volumeDataRequest.requestID)
class VolumeDataRequest(object):
def __init__(self, accessManager: openvds.core.VolumeDataAccessManager, layout: openvds.core.VolumeDataLayout, data_out: np.array = None, dimensionsND: DimensionsND = DimensionsND.Dimensions_012, lod: int = 0, channel: int = 0, min: Tuple[int] = None, max: Tuple[int] = None, format: VoxelFormat = VoxelFormat.Format_R32, replacementNoValue = None):
array_interface = None
......@@ -77,7 +87,9 @@ class VolumeDataRequest(object):
self._iscanceled = False
self._iscompleted = False
@property
self._finalizer = weakref.finalize(self, _finalizeVolumeDataRequest, self)
@property
def isCompleted(self):
"""Has request completed successfully"""
if self._iscompleted:
......@@ -86,7 +98,7 @@ class VolumeDataRequest(object):
return False
self._iscompleted = True if self._accessManager.isCompleted(self.requestID) else False
return self._iscompleted
@property
def isCanceled(self):
"""Has request been canceled"""
......@@ -111,7 +123,7 @@ class VolumeDataRequest(object):
if self.isCompleted:
raise RuntimeError("Operation already completed")
if not self.isCanceled:
self._accessManager.Cancel(self.requestID)
self._accessManager.cancel(self.requestID)
def waitForCompletion(self, timeout = 0.0):
"""Wait for request to complete, or time out after a specified amount of time.
......@@ -131,7 +143,8 @@ class VolumeDataRequest(object):
if not self.isCompleted:
nMillisecondsBeforeTimeout = int(timeout * 1000)
self._iscompleted = True if self._accessManager.waitForCompletion(self.requestID, nMillisecondsBeforeTimeout) else False
return self.isCompleted
return self.isCompleted
class VolumeDataSubsetRequest(VolumeDataRequest):
"""Encapsulates volume data subset request.
......@@ -159,6 +172,7 @@ class VolumeDataSubsetRequest(VolumeDataRequest):
else:
self.requestID = self._accessManager.requestVolumeSubset(self._data_out, self._layout, self.dimensionsND, self.lod, self.channel, self.min, self.max, self.format, self.replacementNoValue)
class ProjectedVolumeDataSubsetRequest(VolumeDataRequest):
"""Encapsulates a projected volume data subset request.
......@@ -546,4 +560,4 @@ class VolumeDataAccessManager(object):
def create3DInterpolatingVolumeDataAccessorR64(self, pageAccessor: VolumeDataPageAccessor=None, replacementNoValue=None, interpolationMethod: InterpolationMethod=InterpolationMethod.Cubic): return self._createVolumeDataAccessor("create3DInterpolatingVolumeDataAccessorR64", pageAccessor, replacementNoValue, interpolationMode)
def create4DInterpolatingVolumeDataAccessorR32(self, pageAccessor: VolumeDataPageAccessor=None, replacementNoValue=None, interpolationMethod: InterpolationMethod=InterpolationMethod.Cubic): return self._createVolumeDataAccessor("create4DInterpolatingVolumeDataAccessorR32", pageAccessor, replacementNoValue, interpolationMode)
def create4DInterpolatingVolumeDataAccessorR64(self, pageAccessor: VolumeDataPageAccessor=None, replacementNoValue=None, interpolationMethod: InterpolationMethod=InterpolationMethod.Cubic): return self._createVolumeDataAccessor("create4DInterpolatingVolumeDataAccessorR64", pageAccessor, replacementNoValue, interpolationMode)
\ No newline at end of file
......@@ -331,6 +331,7 @@ bool VolumeDataRequestProcessor::IsCanceled(int64_t jobID)
SetErrorForJob(job);
m_manager.SetCurrentDownloadError(job->completedError);
m_jobs.erase(job_it);
fmt::print(stderr, "C++ cancelledand removed\n");
return true;
}
return false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment