Written by

👨‍💻 InterSystems IRIS Specialist
Question Andrew Sklyarov · Apr 18

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 in OnInit(), and use it through messages from dynamically created 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 keeps our Python object, waits for the requests, processes them using the object, and sends the result back to the IRIS host process. Basically the same as before, but not from the IRIS level. 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

Comments

Andrew Sklyarov  Apr 18 to Robert Cemper

It's interesting, thanks! Need to dig deeper...

0
Andrew Sklyarov  Apr 18 to Dmitry Maslennikov

Yeah... As far as I understand, this is also an implementation of the "External daemon" approach, right? Generally, the same as the RPyC library, but built into Python

0
Eduard Lebedyuk · Apr 20

I'd use a Business Operation approach. Did it for Community Python Gateway, and it worked pretty well.

0