Solved

Python Shutdown script not executed

  • 10 December 2015
  • 11 replies
  • 14 views

Userlevel 2
Badge +12

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()

icon

Best answer by erik_jan 18 December 2015, 22:34

View original

11 replies

Badge

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

Userlevel 4
Badge +13

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.

Userlevel 4

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

Userlevel 2
Badge +12

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():

Userlevel 4

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

Badge

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.

Userlevel 4

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.

Badge

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"

Userlevel 4

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.

Userlevel 2
Badge +12

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 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?

Reply