class_docstr: Registers a session with a Sherpa Study via the port of the database.
  
  This function is called from trial-scripts only.
  
  Attributes:
      host (str): the host that runs the database. Passed host, host set via
          environment variable or 'localhost' in that order.
      port (int): port that database is running on. Passed port, port set via
          environment variable or 27010 in that order.
class_docstr_tok: ["Registers","a","session","with","a","Sherpa","Study","via","the","port","of","the","database",".","This","function","is","called","from","trial-scripts","only",".","Attributes",":","host","(","str",")",":","the","host","that","runs","the","database",".","Passed","host",",","host","set","via","environment","variable","or","'localhost","'","in","that","order",".","port","(","int",")",":","port","that","database","is","running","on",".","Passed","port",",","port","set","via","environment","variable","or","27010","in","that","order","."]
docstr: Returns the next trial from a Sherpa Study.
  
  Returns:
      sherpa.core.Trial: The trial to run.
docstr_tok: ["Returns","the","next","trial","from","a","Sherpa","Study",".","Returns",":","sherpa.core.Trial",":","The","trial","to","run","."]
code: def get_trial(self):
      """
      Returns the next trial from a Sherpa Study.
  
      Returns:
          sherpa.core.Trial: The trial to run.
      """
      if self.test_mode:
          return sherpa.Trial(id=1, parameters={})
  
      assert os.environ.get(
          "SHERPA_TRIAL_ID"
      ), "Environment-variable SHERPA_TRIAL_ID not found. Scheduler needs to set this variable in the environment when submitting a job"
      trial_id = int(os.environ.get("SHERPA_TRIAL_ID"))
      for _ in range(5):
          g = (
              entry
              for entry in self.db.trials.find({"trial_id": trial_id})
          )
          t = next(g)
          if t:
              break
          time.sleep(10)
      if not t:
          raise RuntimeError("No Trial Found!")
      return sherpa.Trial(
          id=t.get("trial_id"), parameters=t.get("parameters")
      )
  
imports: import logging
  import numpy
  import pymongo
  from pymongo import MongoClient
  import subprocess
  import time
  import os
  import socket
  import warnings
  import sherpa
label_desc: Use image node_id 2 for calling the Client obj's underlying member method code with example usage: obj.get_trial() and returns: sherpa, sherpa