I've got 2 scripts - master scripts runs via WorkspaceRunner slave one. Into slave workspaceI've placed specified Python code as shutdown script to print on console some summaries. When run master script via command line - there are no prints from slave script.
Unfortunately that isn't possible for a couple of reasons:
- Print statements are not sent to the FME log file, only to the display (either command line window or the translation log window)
- The child workspace and the master workspace have separate log files
- Furthermore, the translation log file has been closed before the shutdown script executes, so you cannot use the FMELogFile() object to output additional text in the log (I'll post a workaround for this below)
A couple of solutions:
Use the shutdown script in the child workspace to write a small file containing the number of features written (fme.featuresWritten) and then pick it up in the main workspace using a FeatureReader after the WorkspaceRunner. You will of course have to configure the WorkspaceRunner to wait for the child workspace to finish for this to work.
Another alternative is to pass the master log file name as a published parameter to the child workspace, then append to it in the child shutdown script as per the workaround below.
To append to the FME translation log file from the shutdown script, you can use something like the following method:
import fme
def logit(filehandle, text):
filehandle.write(text + '\r\n')
filehandle.flush()
with open (fme.logFileName, 'a') as fmelog:
if fme.status:
logit(fmelog, 'It was a success!')
else:
logit(fmelog, 'Shucks, something went wrong!')
Note that this does not prefix the lines with the timestamp etc, you will have to implement this yourself.