Using the advice in the answers to this question, I created a new type (_NotInFile) and singleton instance (NotInFile) to represent a special condition in a series of IronPython scripts. I tested my implementation in Python and IronPython (from the command line) and saw the correct and expected behavior.
I then passed my code to a colleague who is using my scripts via the dynamic scripting capabilities of C# in a large Visual Studio project. Using the exact same script, he sees the expression itm.data_attr is NotInFile
return false
when inspection of the value in itm.data_attr
unequivocally shows that it is of type _NotInFile and can only be the singleton instance I created.
To be clear, my colleague is not making use of the NotInFile object himself. Instead, he is calling one of my scripts which instantiates a collection of objects (some of which have properties which are assigned the NotInFile singleton) and then, without operating on the collection at all, calling another one of my scripts to process the collection. When I make the same calls (from a command-line test script) the is
operator performs as expected, when he does the same thing it appears to fail.
The only thing I can think of is that C# may be instantiating a separate "copy" of IronPython for the calls to the ingestion and processing scripts, and that each copy instantiates it's own copy of the singleton at a different memory address so that singleton instantiated in the second script is not, in fact, the same object as the stored reference to the singleton instantiated in the first script.
Have I correctly identified the problem? If so, can the C # dynamic scripting system be instructed to run two separate scripts in the same instance of IronPython?