23#include <sys/socket.h>
58 if (
gSystem->GetSysInfo(&si) == 0)
76 l =
fMon.GetListOfDeActives();
92 template<
class FPTYPE>
98 if (!Py_IsInitialized || !Py_IsInitialized())
return;
130 std::string basePath =
"/tmp/ROOTMP-";
135 unsigned nWorker = 0;
138 int ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
140 Error(
"TMPClient::Fork",
"[E][C] Could not create socketpair. Error n. . Now retrying.\n%d", errno);
157 TSocket *s =
new TSocket(sockets[0], (std::to_string(pid)).c_str());
162 Error(
"TMPClient::Fork",
"[E][C] Could not connect to worker with pid %d. Giving up.\n", pid);
179 if (signalHandlers && signalHandlers->
GetSize() > 0)
182 gSystem->RemoveSignalHandler(sh);
187 for (
auto h : *fileHandlers) {
196 std::unique_ptr<TList> lofact(
fMon.GetListOfActives());
197 while (lofact && (lofact->GetSize() > 0)) {
199 lofact.reset(
nullptr);
202 lofact.reset(
fMon.GetListOfActives());
205 std::unique_ptr<TList> lofdeact(
fMon.GetListOfDeActives());
206 while (lofdeact && (lofdeact->GetSize() > 0)) {
208 lofdeact.reset(
nullptr);
211 lofdeact.reset(
fMon.GetListOfDeActives());
227 server.
Init(sockets[1], nWorker);
261 std::unique_ptr<TList> lp(
fMon.GetListOfActives());
263 if (count == nMessages)
269 Error(
"TMPClient:Broadcast",
"[E] Could not send message to server\n");
316 waitpid(pid,
nullptr, 0);
336 unsigned code = msg.first;
341 Error(
"TMPClient::HandleMPCode",
"[I][C] message received: %s\n", str);
343 Error(
"TMPClient::HandleMPCode",
"[E][C] error message received: %s\n", str);
346 Error(
"TMPClient::HandleMPCode",
"[I][C] shutdown notice received from %s\n", str);
349 Error(
"TMPClient::HandleMPCode",
"[W][C] unknown code received. code=%d\n", code);
int MPSend(TSocket *s, unsigned code)
Send a message with the specified code on the specified socket.
T ReadBuffer(TBufferFile *buf)
One of the template functions used to read objects from messages.
std::pair< unsigned, std::unique_ptr< TBufferFile > > MPCodeBufPair
An std::pair that wraps the code and optional object contained in a message.
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
externTGuiFactory * gGuiFactory
externTGuiFactory * gBatchGuiFactory
externTVirtualX * gGXBatch
Class to acquire and release the Python GIL where it applies, i.e.
void *(*)(void) PyGILState_Ensure_type
void(*)(void *) PyGILState_Release_type
int(*)(void) Py_IsInitialized_type
FPTYPE GetSymT(const char *name)
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
unsigned fNWorkers
The number of workers that should be spawned upon forking.
TMPClient(unsigned nWorkers=0)
Class constructor.
unsigned Broadcast(unsigned code, unsigned nMessages=0)
Send a message with the specified code to at most nMessages workers.
std::vector< pid_t > fWorkerPids
A vector containing the PIDs of children processes/workers.
~TMPClient()
Class destructor.
TMonitor fMon
This object manages the sockets and detect socket events via TMonitor::Select.
void HandleMPCode(MPCodeBufPair &msg, TSocket *sender)
Handle messages containing an EMPCode.
void ReapWorkers()
Wait on worker processes and remove their pids from fWorkerPids.
void Remove(TSocket *s)
Remove a certain socket from the monitor.
bool Fork(TMPWorker &server)
This method forks the ROOT session into fNWorkers children processes.
bool fIsParent
This is true if this is the parent/client process, false if this is a child/worker process.
void DeActivate(TSocket *s)
DeActivate a certain socket.
This class works in conjuction with TMPClient, reacting to messages received from it as specified by ...
virtual void Init(int fd, unsigned workerN)
This method is called by children processes right after forking.
Sequenceable collection abstract base class.
virtual TObject * First() const =0
This class implements client sockets.
virtual Bool_t IsValid() const
@ kMessage
Generic message.
@ kFatalError
Fatal error: whoever sends this message is terminating execution.
@ kShutdownOrder
Used by the client to tell servers to shutdown.
@ kShutdownNotice
Used by the workers to notify client of shutdown.