Skip to main content
Solved

Python Shutdown script not executed


erik_jan
Contributor
Forum|alt.badge.img+18

Anybody an idea why this combination would not work?

The Shutdown script seems to not executed.

Startup script

def initializeArcFM():

import win32com.client

global app

app = win32com.client.Dispatch('Miner.Framework.Dispatch.MMAppInitializeDispatch')

runtime = win32com.client.Dispatch('Miner.Framework.Dispatch.MMRuntimeEnvironmentDispatch')

app.Initialize(0x5)

runtime.RuntimeMode = 0x4

print "ArcFM runtime mode", runtime.RuntimeMode

def cleanupArcFM():

global app

if app:

app.Shutdown

del app

print "ArcFM shutdown"

initializeArcFM()

Shutdown script

cleanupArcFM()

Best answer by erik_jan

Hi All,

Thanks for the huge amount of ideas.

Safe support (@LauraAtSafe) figured it out after all:

The problem was in the FME Server engine reloading Python after each run.

This caused the script to fail the second time it was run on the same FME Server engine.

The solution was in setting the FME Server setting FME_ENGINE_PYTHON_RELOAD to false.

This issue was solved in FME Sever 2015 and should not appear anymore.

So the Python script in itself was working as designed.

Thanks again.

View original
Did this help you find an answer to your question?

11 replies

Forum|alt.badge.img+5
  • December 12, 2015

Can you format your code please ? or a screenshot in FME Desktop.

Where is the error in log file ?

cleanupArcFM is defined in Startup Script and you call your def in Shutdown script. May be the best thing is to put the same def in Shutdown script


fmelizard
Safer
Forum|alt.badge.img+19
  • Safer
  • December 12, 2015
julien wrote:

Can you format your code please ? or a screenshot in FME Desktop.

Where is the error in log file ?

cleanupArcFM is defined in Startup Script and you call your def in Shutdown script. May be the best thing is to put the same def in Shutdown script

Yes the log should be interesting. The only way we wouldn't invoke the shutdown python is if the whole translation were going down hard.


david_r
Celebrity
  • December 14, 2015

I agree with the others, you need to post the formatted code, as indenting is meaningful in Python.

Having said that, you could probably simplify your debugging a fair bit by dropping the function definitions and just doing everything line-by-line, in a sequential order. Would probably look something like this:

import win32com.client
app = win32com.client.Dispatch('Miner.Framework.Dispatch.MMAppInitializeDispatch')
runtime = win32com.client.Dispatch('Miner.Framework.Dispatch.MMRuntimeEnvironmentDispatch')
app.Initialize(0x5)
runtime.RuntimeMode = 0x4
print "ArcFM runtime mode", runtime.RuntimeMode
if app:
    app.Shutdown
del app
print "ArcFM shutdown"

David


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • December 14, 2015

Sorry about the lack of indentation (I know it is important, but it fell away copying it from an email).

Here is the better text:

The FME log shows this Error:

Python Exception <TypeError>: 'NoneType' object is not callable

Error executing string `def initializeArcFM():


david_r
Celebrity
  • December 15, 2015
erik_jan wrote:

Sorry about the lack of indentation (I know it is important, but it fell away copying it from an email).

Here is the better text:

The FME log shows this Error:

Python Exception <TypeError>: 'NoneType' object is not callable

Error executing string `def initializeArcFM():

The error message indicates that either of the 'app' or 'runtime' objects failed to initialize.

Maybe try manually typing the commands into idle or something to see exactly what the error is


Forum|alt.badge.img+5
  • December 17, 2015
erik_jan wrote:

Sorry about the lack of indentation (I know it is important, but it fell away copying it from an email).

Here is the better text:

The FME log shows this Error:

Python Exception <TypeError>: 'NoneType' object is not callable

Error executing string `def initializeArcFM():

Can you explain to us, why the definition is in Startup and the call is just in Shutdown ? I don't think there is a communication between the startup and shutdown script.


david_r
Celebrity
  • December 17, 2015
julien wrote:

Can you explain to us, why the definition is in Startup and the call is just in Shutdown ? I don't think there is a communication between the startup and shutdown script.

I think all Python code inside a single running workspace is executed inside the same instance of the Python interpreter. That is why it is possible to define global objects in e.g. a PythonCaller and then reference them in the shutdown script. So technically I would assume the above to work, although I agree that it is a bit weird ;-)

A somewhat interesting exception is if you use Python-based transformers in the workspace (notably the StatisticsCalculator), which re-initalizes the Python interpreter on the first feature, making you lose everything that was defined in before that point.


Forum|alt.badge.img+5
  • December 18, 2015
david_r wrote:

I think all Python code inside a single running workspace is executed inside the same instance of the Python interpreter. That is why it is possible to define global objects in e.g. a PythonCaller and then reference them in the shutdown script. So technically I would assume the above to work, although I agree that it is a bit weird ;-)

A somewhat interesting exception is if you use Python-based transformers in the workspace (notably the StatisticsCalculator), which re-initalizes the Python interpreter on the first feature, making you lose everything that was defined in before that point.

You need to have a confirmation from Safe from this point: "all Python code inside a single running workspace is executed inside the same instance of the Python interpreter"


david_r
Celebrity
  • December 18, 2015
julien wrote:

You need to have a confirmation from Safe from this point: "all Python code inside a single running workspace is executed inside the same instance of the Python interpreter"

I agree, that would be ideal. However, it is pretty easy to test for using global variables. So far, it seems to hold true, and I take advantage of it quite often.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Author
  • Contributor
  • Best Answer
  • December 18, 2015

Hi All,

Thanks for the huge amount of ideas.

Safe support (@LauraAtSafe) figured it out after all:

The problem was in the FME Server engine reloading Python after each run.

This caused the script to fail the second time it was run on the same FME Server engine.

The solution was in setting the FME Server setting FME_ENGINE_PYTHON_RELOAD to false.

This issue was solved in FME Sever 2015 and should not appear anymore.

So the Python script in itself was working as designed.

Thanks again.


erik_jan wrote:

Hi All,

Thanks for the huge amount of ideas.

Safe support (@LauraAtSafe) figured it out after all:

The problem was in the FME Server engine reloading Python after each run.

This caused the script to fail the second time it was run on the same FME Server engine.

The solution was in setting the FME Server setting FME_ENGINE_PYTHON_RELOAD to false.

This issue was solved in FME Sever 2015 and should not appear anymore.

So the Python script in itself was working as designed.

Thanks again.

Hi Erik_jan, can I ask if you install pythonwin for your script to run?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings