How to create a processes-shared singleton in IRIS?
I need a %SYS.Python object that will be accessible from different processes. The goal is to avoid reinitializing the Python object whenever it is called. Ways that I checked and decided that it is NOT what I want:
- %-variables (process variables). Reusing only in the same process
- Save-and-restore via globals. Restoring means heavy initialization, which I want to avoid
Next, my ideas (none of them look like a silver bullet):
- Using Interoperability Production. We create a Business Operation, set enough
PoolSize, initialize our Python object inOnInit(), and use it through a dynamic creation of Business Service:
Set tSC = ##class(Ens.Director).CreateBusinessService("MyService", .service)
Return:$$$ISERR(tSC) tSC
Set tSC = service.SendRequestSync(operationHostName, req, .resp)- External daemon. Some service that waits for the requests, processes them, and sends the result back to the IRIS host process. We can use different protocols, message systems, and so on. But I believe the easiest way is the FastAPI API over HTTP. Because IRIS has a built-in HTTP client, there is no need for additional objects/libs for integration. Local HTTP calls must be fast enough...
Update: I googled it a bit. Maybe I am wrong about FastAPI as the simplest way. RPyC lib looks good too.
I missed something?
I know how to create an in-process singleton. But my question is about interprocess communication.
Product version: IRIS 2025.3
Discussion (2)0
Comments
As you mentioned, InterProcessCommunication, it might be worth taking
a look at my Article + Demo on OEX
Using Interjob Communication (IJC) + InterJob-communication
Did you check SharedMemory in Python?