class_docstr: Base class for an RPC server using `torch.distributed`.
  Users should subclass this class and add the server methods.
  
  Example:
      init_method = "file://myfile.tmp"
      num_clients = 1
      torch.distributed.init_process_group('gloo',
                                           init_method=init_method,
                                           world_size=num_clients + 1,
                                           rank=0)
  
      class MyServer(Server):
          def test_func(self, T, k=0):
              return ("the result is ", T + k)
  
      s = MyServer(num_clients)
      s.start()  # will block until all clients have called `join()`
class_docstr_tok: ["Base","class","for","an","RPC","server","using","`","torch.distributed","`",".","Users","should","subclass","this","class","and","add","the","server","methods",".","Example",":","init_method","=","``","file",":","\/\/myfile.tmp","''","num_clients","=","1","torch.distributed.init_process_group","(","'gloo","'",",","init_method=init_method",",","world_size=num_clients","+","1",",","rank=0",")","class","MyServer","(","Server",")",":","def","test_func","(","self",",","T",",","k=0",")",":","return","(","``","the","result","is","``",",","T","+","k",")","s","=","MyServer","(","num_clients",")","s.start","(",")","#","will","block","until","all","clients","have","called","`","join","(",")","`"]
code: def start(self, groups=None):
      join_clients = []
  
      while True:
          rpc, src = recv()
          if rpc == _JOIN_KEY:
              join_clients += [src]
              if len(join_clients) == self.num_clients:
                  for client in join_clients:
                      # after sending the join cmd,
                      # each client waits on this ack to know everyone is done
                      # and it's safe to exit
                      send(_JOIN_KEY, client)
                  break
          else:
              F, args, kwargs = rpc
              try:
                  res = getattr(self, F)(*args, **kwargs)
                  send((False, res), src)
              except BaseException as e:
                  # should we print the exception on the server also?
                  # traceback.print_exc()
                  exc_str = traceback.format_exc()
                  send((True, (e, exc_str)), src)
  
file_path: PyTorch-BigGraph/torchbiggraph/rpc.py
imports: import io
  import sys
  import traceback
  import numpy
  import torch
  import torch.distributed
label_desc: Use image node_id 2 for calling the Server obj's underlying member method code with example usage: obj.start(groups) without return types