How to stop Pengine self-destruction? (destruct parameter is False)

Yes, a Pengine is a thread that operates on a temporary module. That it where it loads src_text. If you assert, data goes there too, so other Pengines do not see your data. Creation is indeed quite cheap, mostly depending how much source code you load into it.

If you want to share data or preserve data longer than the Pengine lives you need to load code into the server that is accessible from the pengine application and manages this data. You must declare this API as safe and you must make sure it is safe and also thread-safe as it will indeed be called concurrently.

If you use Pengines for agent modelling it may be a good idea to the temporary model to store the status of the agent and use the idle limit to keep it alive.

2 Likes