Skip to main content
Solved

[Python] How to access from master workspace to fme.featuresWritten from slave workspace?

  • September 7, 2016
  • 2 replies
  • 23 views

arekpierchala
Contributor
Forum|alt.badge.img+1

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.

Best answer by david_r

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • Best Answer
  • September 7, 2016

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.


david_r
Celebrity
  • September 7, 2016

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.