Question

May I use FME Objects in Startup / Shutdown Python Script?

  • 8 October 2013
  • 6 replies
  • 2 views

Userlevel 2
Badge +17
Hi,

 

 

"Shutdown python scripts can make use of FME Objects by using import fmeobjects" -- Startup and Shutdown Python and Tcl Scripts   However, when I try to create an FME Object (e.g. fmeobjects.FMELicenseManager) in Startup or Shutdown Python Script, FME always shows this warning message in the Log window finally.

 

  Warning: not all FMESessions that were created were destroyed before shutdown.  This may cause instability

 

The workspace works without errors, just this warning occurs. May I ignore this message? or Creating FME Objects is not recommended in Startup / Shutdown script?

 

 

Takashi

6 replies

Userlevel 4
Hi Takashi,

 

 

I have seen this warning a lot but never really experienced any instability that I could link to this issue.

 

 

However, the warning seems to disappear if you manually destroy your fmeobject class instances before your script terminates. Example:

 

 

-----

 

import fmeobjects myobj = fmeobjects.FMELicenseManager()   print "hello world"

 

# Manually free the FMELicenseManager instance del myobj

 

-----

 

 

It seems a bit non-Pythonic to me that this is necessary in FME, but there you go. You could perhaps flag this as an issue with Safe.

 

 

Tested using FME2013sp3

 

 

David
Userlevel 2
Badge +17
Hi David,   Thanks for the answer.

 

I confirmed the warning disappear if I destroy the instance manually with del statement.

 

It's non-Pythonic indeed as you say.

 

I will ask to Safe, and report the result here.   Takashi
Userlevel 2
Badge +17
Sharing the answer from Safe.

 

 

Answer from Safe "The Python FMEObjects API is a wrapper around the native C++ API, and so requires some garbage collection not normally done in Python. Setting your FMEObjects objects to None to destroy them once you no longer need them will prevent the FMESessions warning. This is not a major issue when running FME Desktop, since FME will clean up after itself when it shuts down, but can cause problems in FME Server, where FME runs constantly."   Test with FME 2013 SP3, Startup / Shutdown Python Script ----- import fmeobjects   # Create an FME object. licMan = fmeobjects.FMELicenseManager()   # Do something using the object   # Destroy the object (flag on garbage collection) licMan = None ----- ... the warning message disappears.

 

  Conclusion When we use FME objects in Startup / Shutdown Python Script, we should explicitly flag on garbage collection (assign None) to destroy them after using. If we didn't destroy them, - It will not be a major issue when running FME Desktop - It can cause problems when running FME Server

 

 

I think "del" statement may be also used to destroy an object.
Userlevel 2
Badge +17
The workspace with this startup script finished without the warning message. ----- import fmeobjects   def startupProcess():     logger = fmeobjects.FMELogFile()     logger.logMessageString('Startup')   startupProcess() -----

 

  Python garbage collector seems to destroy objects created in a local scope when the scope finished. This style may be better than creating FME objects in the global scope, to prevent unexpected problems caused by forgetting to destroy them.
Userlevel 2
Badge +17
In short; assume a variable is the last one which refers to the object, the Python garbage collector seems to collect it (and destroy it as soon as possible) at these points: - the variable has become to refer to another object (e.g. None). - the variable has been deleted explicitly with del statement. - scope of the variable has been finished.   The mist has cleared up :-)
Badge

I encountered this also. In my case not solved by del statements until I moved code inside a def. Then all working ok.

Reply