fix python nodes being blocked by log

...when ran on command line with meshroom_photogrammetry or meshroom_compute
This commit is contained in:
ChemicalXandco 2020-02-07 22:47:27 +00:00
parent 95a28cb0a7
commit f75fc91436
3 changed files with 58 additions and 64 deletions

View file

@ -132,9 +132,6 @@ class LogManager:
def __init__(self, chunk):
self.chunk = chunk
self.chunk.statusChanged.connect(self.clear)
self.progressBar = False
self.cleared = False
self.logger = logging.getLogger(chunk.node.getName())
class Formatter(logging.Formatter):
@ -151,27 +148,22 @@ class LogManager:
handler.setFormatter(formatter)
self.logger.addHandler(handler)
def clear(self):
if self.chunk.statusName == 'RUNNING' and not self.cleared:
open(self.chunk.logFile, 'w').close()
self.configureLogger()
self.cleared = True
# When the node gets ran again the log needs to be cleared
elif self.chunk.statusName in ['ERROR', 'SUCCESS']:
for handler in self.logger.handlers[:]:
# Stops the file being locked
handler.close()
self.cleared = False
self.progressBar = False
def start(self, level):
# Clear log file
open(self.chunk.logFile, 'w').close()
self.configureLogger()
self.logger.setLevel(self.textToLevel(level))
self.progressBar = False
def waitUntilCleared(self):
while not self.cleared:
time.sleep(0.01)
def end(self):
for handler in self.logger.handlers[:]:
# Stops the file being locked
handler.close()
def makeProgressBar(self, end, message=''):
assert end > 0
assert not self.progressBar
self.waitUntilCleared()
self.progressEnd = end
self.currentProgressTics = 0
@ -194,7 +186,6 @@ class LogManager:
def updateProgressBar(self, value):
assert self.progressBar
assert value <= self.progressEnd
self.waitUntilCleared()
tics = round((value/self.progressEnd)*51)

View file

@ -50,27 +50,29 @@ class Publish(desc.Node):
return paths
def processChunk(self, chunk):
chunk.logManager.waitUntilCleared()
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))
if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to publish')
return
if not chunk.node.output.value:
return
try:
chunk.logManager.start(chunk.node.verboseLevel.value)
if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to publish')
return
if not chunk.node.output.value:
return
outFiles = self.resolvedPaths(chunk.node.inputFiles.value, chunk.node.output.value)
outFiles = self.resolvedPaths(chunk.node.inputFiles.value, chunk.node.output.value)
if not outFiles:
error = 'Publish: input files listed, but nothing to publish'
chunk.logger.error(error)
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
raise RuntimeError(error)
if not outFiles:
error = 'Publish: input files listed, but nothing to publish'
chunk.logger.error(error)
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
raise RuntimeError(error)
if not os.path.exists(chunk.node.output.value):
os.mkdir(chunk.node.output.value)
if not os.path.exists(chunk.node.output.value):
os.mkdir(chunk.node.output.value)
for iFile, oFile in outFiles.items():
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
shutil.copyfile(iFile, oFile)
chunk.logger.info('Publish end')
for iFile, oFile in outFiles.items():
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
shutil.copyfile(iFile, oFile)
chunk.logger.info('Publish end')
finally:
chunk.logManager.end()

View file

@ -216,31 +216,30 @@ class SketchfabUpload(desc.Node):
return self._stopped
def processChunk(self, chunk):
self._stopped = False
chunk.logManager.waitUntilCleared()
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))
if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to upload')
return
if chunk.node.apiToken.value == '':
chunk.logger.error('Need API token.')
raise RuntimeError()
if len(chunk.node.title.value) > 48:
chunk.logger.error('Title cannot be longer than 48 characters.')
raise RuntimeError()
if len(chunk.node.description.value) > 1024:
chunk.logger.error('Description cannot be longer than 1024 characters.')
raise RuntimeError()
tags = [ i.value.replace(' ', '-') for i in chunk.node.tags.value.values() ]
if all(len(i) > 48 for i in tags) and len(tags) > 0:
chunk.logger.error('Tags cannot be longer than 48 characters.')
raise RuntimeError()
if len(tags) > 42:
chunk.logger.error('Maximum of 42 separate tags.')
raise RuntimeError()
try:
self._stopped = False
chunk.logManager.start(chunk.node.verboseLevel.value)
if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to upload')
return
if chunk.node.apiToken.value == '':
chunk.logger.error('Need API token.')
raise RuntimeError()
if len(chunk.node.title.value) > 48:
chunk.logger.error('Title cannot be longer than 48 characters.')
raise RuntimeError()
if len(chunk.node.description.value) > 1024:
chunk.logger.error('Description cannot be longer than 1024 characters.')
raise RuntimeError()
tags = [ i.value.replace(' ', '-') for i in chunk.node.tags.value.values() ]
if all(len(i) > 48 for i in tags) and len(tags) > 0:
chunk.logger.error('Tags cannot be longer than 48 characters.')
raise RuntimeError()
if len(tags) > 42:
chunk.logger.error('Maximum of 42 separate tags.')
raise RuntimeError()
data = {
'name': chunk.node.title.value,
'description': chunk.node.description.value,
@ -276,5 +275,7 @@ class SketchfabUpload(desc.Node):
os.remove(uploadFile)
chunk.logger.debug('Deleted {}'.format(uploadFile))
chunk.logManager.end()
def stopProcess(self, chunk):
self._stopped = True