当前位置: 首页>>代码示例>>Python>>正文


Python Controller.start方法代码示例

本文整理汇总了Python中Controller.Controller.start方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.start方法的具体用法?Python Controller.start怎么用?Python Controller.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller.Controller的用法示例。


在下文中一共展示了Controller.start方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
    parser = OptionParser()
    parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False)
    parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None)
    parser.add_option("--host", dest="host", help="AppMaster host", default=None)
    parser.add_option("--port", dest="port", help="AppMaster port", default=None)
    (options, args) = parser.parse_args()

    if not "AGENT_WORK_ROOT" in os.environ:
        parser.error("AGENT_WORK_ROOT environment variable must be set.")
    options.root_folder = os.environ["AGENT_WORK_ROOT"]
    if not "AGENT_LOG_ROOT" in os.environ:
        parser.error("AGENT_LOG_ROOT environment variable must be set.")
    options.log_folder = os.environ["AGENT_LOG_ROOT"]
    if not options.label:
        parser.error("label is required.")

    bind_signal_handlers()

    # Check for configuration file.
    agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label)
    update_config_from_file(agentConfig)

    # update configurations if needed
    if options.host:
        agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", options.host)

    if options.port:
        agentConfig.set(AgentConfig.SERVER_SECTION, "port", options.port)

    logFile = os.path.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName)
    perform_prestart_checks(agentConfig)
    ensure_folder_layout(agentConfig)

    setup_logging(options.verbose, logFile)
    update_log_level(agentConfig, logFile)
    write_pid()

    logger.info("Using AGENT_WORK_ROOT = " + options.root_folder)
    logger.info("Using AGENT_LOG_ROOT = " + options.log_folder)

    server_url = SERVER_STATUS_URL.format(
        agentConfig.get(AgentConfig.SERVER_SECTION, "hostname"),
        agentConfig.get(AgentConfig.SERVER_SECTION, "port"),
        agentConfig.get(AgentConfig.SERVER_SECTION, "check_path"),
    )
    print("Connecting to the server at " + server_url + "...")
    logger.info("Connecting to the server at: " + server_url)

    # Wait until server is reachable
    netutil = NetUtil()
    netutil.try_to_connect(server_url, -1, logger)

    # Launch Controller communication
    controller = Controller(agentConfig)
    controller.start()
    controller.join()
    stop_agent()
    logger.info("... agent finished")
开发者ID:jagatsingh,项目名称:slider,代码行数:61,代码来源:main.py

示例2: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
	# set up logging for the application
	
	logger.info("Starting BreakfastAlarm App for user: {}".format(user_id))

	controller = Controller(user_id, logger)
	controller.set_profile(get_breakfast_profile())
	controller.start()
开发者ID:SpencerDodd,项目名称:BreakfastAlarm,代码行数:10,代码来源:main.py

示例3: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
  global config
  parser = OptionParser()
  parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False)
  parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store",
                    help="expected hostname of current host. If hostname differs, agent will fail", default=None)
  (options, args) = parser.parse_args()

  expected_hostname = options.expected_hostname

  setup_logging(options.verbose)

  default_cfg = { 'agent' : { 'prefix' : '/home/ambari' } }
  config = ConfigParser.RawConfigParser(default_cfg)
  bind_signal_handlers()

  if (len(sys.argv) >1) and sys.argv[1]=='stop':
    stop_agent()

  # Check for ambari configuration file.
  config = resolve_ambari_config()

  # Starting data cleanup daemon
  data_cleaner = None
  if int(config.get('agent','data_cleanup_interval')) > 0:
    data_cleaner = DataCleaner(config)
    data_cleaner.start()

  perform_prestart_checks(expected_hostname)
  daemonize()

  # Starting ping port listener
  try:
    ping_port_listener = PingPortListener(config)
  except Exception as ex:
    err_message = "Failed to start ping port listener of: " + str(ex)
    logger.error(err_message);
    sys.stderr.write(err_message)
    sys.exit(1)
  ping_port_listener.start()

  update_log_level(config)

  server_url = 'https://' + config.get('server', 'hostname') + ':' + config.get('server', 'url_port')
  print("Connecting to the server at " + server_url + "...")
  logger.info('Connecting to the server at: ' + server_url)

  # Wait until server is reachable
  netutil = NetUtil()
  netutil.try_to_connect(server_url, -1, logger)

  # Launch Controller communication
  controller = Controller(config)
  controller.start()
  controller.join()
  stop_agent()
  logger.info("finished")
开发者ID:wbear2,项目名称:ambari,代码行数:59,代码来源:main.py

示例4: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
        
        #Create new threads
        comedi = ComediCom()
        mon = Monitor()
        Gui_Thread = GUI(mon, comedi)
        RefThread = ReferenceGenerator(mon)
        ControlThread = Controller(mon, comedi)

        # set daemon = True to connect all threads exit states such that when one exits, all does
        ControlThread.daemon = True
        RefThread.daemon = True

        # Start new Threads
        ControlThread.start()
        Gui_Thread.start()
        RefThread.start()
开发者ID:liniii,项目名称:Real_time_sys_project,代码行数:19,代码来源:Main.py

示例5: Image

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
timers = Image(timerImage)

clockImage = PILImage.new('RGB', (64, 32))
clock = Image(clockImage)

# Tread creation
logging.info("Creating threads")
clkThread = Clock(clock, (64, 32), position=(0, 0), color=(255, 0, 0, 255))
threads.append(clkThread)

tmrThread1 = Timer(timers, (32, 16), minutes=1, position=(0, 0), offset=(0, -6), color=(0, 0, 255, 255))
tmrThread2 = Timer(timers, (32, 16), minutes=1, position=(0, 16), offset=(0, -6), color=(255, 255, 0, 255))
tmrThread3 = Timer(timers, (32, 16), minutes=2, position=(32, 0), offset=(0, -6), color=(255, 0, 0, 255))
tmrThread4 = Timer(timers, (32, 16), minutes=2, position=(32, 16), offset=(0, -6), color=(255, 255, 255, 255))

threads.append(tmrThread1)
threads.append(tmrThread2)
threads.append(tmrThread3)
threads.append(tmrThread4)

logging.info("Starting control thread")
controller = Controller(threads)
controller.start()

logging.info("Entering wait loop")
while True:
    matrix.SetImage(timerImage.im.id, 0, 0)

    # Sleep to get to 60FPS
    time.sleep(0.16)
开发者ID:agreenspan,项目名称:roundtimer,代码行数:32,代码来源:RoundTimer.py

示例6: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
  parser = OptionParser()
  parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False)
  parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None)
  parser.add_option("--zk-quorum", dest=Constants.ZK_QUORUM, help="Zookeeper Quorum", default=None)
  parser.add_option("--zk-reg-path", dest=Constants.ZK_REG_PATH, help="Zookeeper Registry Path", default=None)
  parser.add_option("--debug", dest="debug", help="Agent debug hint", default="")
  (options, args) = parser.parse_args()

  if not Constants.AGENT_WORK_ROOT in os.environ and not 'PWD' in os.environ:
    parser.error("AGENT_WORK_ROOT environment variable or PWD must be set.")
  if Constants.AGENT_WORK_ROOT in os.environ:
    options.root_folder = os.environ[Constants.AGENT_WORK_ROOT]
  else:
    # some launch environments do not end up setting all environment variables
    options.root_folder = os.environ['PWD']

  if not 'AGENT_LOG_ROOT' in os.environ:
    parser.error("AGENT_LOG_ROOT environment variable must be set.")
  options.log_folder = os.environ['AGENT_LOG_ROOT']
  all_log_folders = [x.strip() for x in options.log_folder.split(',')]
  if len(all_log_folders) > 1:
    options.log_folder = all_log_folders[0]

  # If there are multiple log folder, separate by comma, pick one

  if not options.label:
    parser.error("label is required.");

  if not IS_WINDOWS:
    bind_signal_handlers()

  # Check for configuration file.
  agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label)
  update_config_from_file(agentConfig)

  # update configurations if needed
  if options.zk_quorum:
      agentConfig.set(AgentConfig.SERVER_SECTION, Constants.ZK_QUORUM, options.zk_quorum)

  if options.zk_reg_path:
      agentConfig.set(AgentConfig.SERVER_SECTION, Constants.ZK_REG_PATH, options.zk_reg_path)

  if options.debug:
    agentConfig.set(AgentConfig.AGENT_SECTION, AgentConfig.APP_DBG_CMD, options.debug)

  logFile = posixpath.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName)
  setup_logging(options.verbose, logFile)
  update_log_level(agentConfig, logFile)

  secDir = posixpath.join(agentConfig.getResolvedPath(AgentConfig.RUN_DIR), "security")
  logger.info("Security/Keys directory: " + secDir)
  agentConfig.set(AgentConfig.SECURITY_SECTION, "keysdir", secDir)

  perform_prestart_checks(agentConfig)
  ensure_folder_layout(agentConfig)
  # create security dir if necessary
  ensure_path_exists(secDir)

  write_pid()

  logger.info("Using AGENT_WORK_ROOT = " + options.root_folder)
  logger.info("Using AGENT_LOG_ROOT = " + options.log_folder)

  if len(all_log_folders) > 1:
    logger.info("Selected log folder from available: " + ",".join(all_log_folders))

  # Extract the AM hostname and secured port from ZK registry
  zk_lookup_tries = 0
  while zk_lookup_tries < Constants.MAX_AM_CONNECT_RETRIES:
    registry = Registry(options.zk_quorum, options.zk_reg_path)
    amHost, amUnsecuredPort, amSecuredPort = registry.readAMHostPort()

    tryConnect = True
    if not amHost or not amSecuredPort or not amUnsecuredPort:
      logger.info("Unable to extract AM host details from ZK, retrying ...")
      tryConnect = False
      time.sleep(NetUtil.CONNECT_SERVER_RETRY_INTERVAL_SEC)

    if tryConnect:
      if amHost:
        agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", amHost)

      if amSecuredPort:
        agentConfig.set(AgentConfig.SERVER_SECTION, "secured_port", amSecuredPort)

      if amUnsecuredPort:
        agentConfig.set(AgentConfig.SERVER_SECTION, "port", amUnsecuredPort)

      server_url = SERVER_STATUS_URL.format(
        agentConfig.get(AgentConfig.SERVER_SECTION, 'hostname'),
        agentConfig.get(AgentConfig.SERVER_SECTION, 'port'),
        agentConfig.get(AgentConfig.SERVER_SECTION, 'check_path'))
      print("Connecting to the server at " + server_url + "...")
      logger.info('Connecting to the server at: ' + server_url)

      # Wait until server is reachable and continue to query ZK
      netutil = NetUtil()
      retries = netutil.try_to_connect(server_url, 3, logger)
      if retries < 3:
#.........这里部分代码省略.........
开发者ID:OpenPOWER-BigData,项目名称:HDP-slider,代码行数:103,代码来源:main.py

示例7: __init__

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
 def __init__(self):
     print "Main init"
     controller = Controller()
     controller.start()
开发者ID:cristian25x,项目名称:BIST,代码行数:6,代码来源:Main.py

示例8: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main():
  parser = OptionParser()
  parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False)
  parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None)
  parser.add_option("--host", dest="host", help="AppMaster host", default=None)
  parser.add_option("--port", dest="port", help="AppMaster port", default=None)
  parser.add_option("--secured_port", dest="secured_port", help="AppMaster 2 Way port", default=None)
  parser.add_option("--debug", dest="debug", help="Agent debug hint", default="")
  (options, args) = parser.parse_args()

  if not 'AGENT_WORK_ROOT' in os.environ:
    parser.error("AGENT_WORK_ROOT environment variable must be set.");
  options.root_folder = os.environ['AGENT_WORK_ROOT']
  if not 'AGENT_LOG_ROOT' in os.environ:
    parser.error("AGENT_LOG_ROOT environment variable must be set.");
  options.log_folder = os.environ['AGENT_LOG_ROOT']
  if not options.label:
    parser.error("label is required.");

  bind_signal_handlers()

  # Check for configuration file.
  agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label)
  update_config_from_file(agentConfig)

  # update configurations if needed
  if options.host:
      agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", options.host)

  if options.port:
      agentConfig.set(AgentConfig.SERVER_SECTION, "port", options.port)

  if options.secured_port:
      agentConfig.set(AgentConfig.SERVER_SECTION, "secured_port", options.secured_port)

  if options.debug:
    agentConfig.set(AgentConfig.AGENT_SECTION, AgentConfig.APP_DBG_CMD, options.debug)

  # set the security directory to a subdirectory of the run dir
  secDir = os.path.join(agentConfig.getResolvedPath(AgentConfig.RUN_DIR), "security")
  logger.info("Security/Keys directory: " + secDir)
  agentConfig.set(AgentConfig.SECURITY_SECTION, "keysdir", secDir)

  logFile = os.path.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName)

  perform_prestart_checks(agentConfig)
  ensure_folder_layout(agentConfig)
  # create security dir if necessary
  ensure_path_exists(secDir)

  setup_logging(options.verbose, logFile)
  update_log_level(agentConfig, logFile)
  write_pid()

  logger.info("Using AGENT_WORK_ROOT = " + options.root_folder)
  logger.info("Using AGENT_LOG_ROOT = " + options.log_folder)

  server_url = SERVER_STATUS_URL.format(
    agentConfig.get(AgentConfig.SERVER_SECTION, 'hostname'),
    agentConfig.get(AgentConfig.SERVER_SECTION, 'port'),
    agentConfig.get(AgentConfig.SERVER_SECTION, 'check_path'))
  print("Connecting to the server at " + server_url + "...")
  logger.info('Connecting to the server at: ' + server_url)

  # Wait until server is reachable
  netutil = NetUtil()
  netutil.try_to_connect(server_url, -1, logger)

  # Launch Controller communication
  controller = Controller(agentConfig)
  controller.start()
  try:
    while controller.is_alive():
      controller.join(timeout=1.0)
  except (KeyboardInterrupt, SystemExit):
    logger.info("... agent interrupted")
    pass
开发者ID:gsaha,项目名称:incubator-slider,代码行数:79,代码来源:main.py

示例9: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main(heartbeat_stop_callback=None):
  global config
  parser = OptionParser()
  parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False)
  parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store",
                    help="expected hostname of current host. If hostname differs, agent will fail", default=None)
  (options, args) = parser.parse_args()

  expected_hostname = options.expected_hostname

  current_user = getpass.getuser()

  setup_logging(options.verbose)
  
  default_cfg = {'agent': {'prefix': '/home/ambari'}}
  config.load(default_cfg)

  bind_signal_handlers(agentPid)

  if (len(sys.argv) > 1) and sys.argv[1] == 'stop':
    stop_agent()

  if (len(sys.argv) > 2) and sys.argv[1] == 'reset':
    reset_agent(sys.argv)

  # Check for ambari configuration file.
  resolve_ambari_config()

  # Starting data cleanup daemon
  data_cleaner = None
  if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0:
    data_cleaner = DataCleaner(config)
    data_cleaner.start()

  perform_prestart_checks(expected_hostname)

  # Starting ping port listener
  try:
    #This acts as a single process machine-wide lock (albeit incomplete, since
    # we still need an extra file to track the Agent PID)
    ping_port_listener = PingPortListener(config)
  except Exception as ex:
    err_message = "Failed to start ping port listener of: " + str(ex)
    logger.error(err_message)
    sys.stderr.write(err_message)
    sys.exit(1)
  ping_port_listener.start()

  update_log_level(config)

  server_hostname = config.get('server', 'hostname')
  server_url = config.get_api_url()

  if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY:
    daemonize()

  try:
    server_ip = socket.gethostbyname(server_hostname)
    logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip)
  except socket.error:
    logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname)

  # Wait until server is reachable
  netutil = NetUtil(heartbeat_stop_callback)
  retries, connected = netutil.try_to_connect(server_url, -1, logger)
  # Ambari Agent was stopped using stop event
  if connected:
    # Launch Controller communication
    controller = Controller(config, heartbeat_stop_callback)
    controller.start()
    controller.join()
  if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY:
    stop_agent()
  logger.info("finished")
开发者ID:fanzhidongyzby,项目名称:ambari,代码行数:76,代码来源:main.py

示例10: main

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
def main(heartbeat_stop_callback=None):
  global config
  parser = OptionParser()
  parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False)
  parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store",
                    help="expected hostname of current host. If hostname differs, agent will fail", default=None)
  (options, args) = parser.parse_args()

  expected_hostname = options.expected_hostname

  logging_level = logging.DEBUG if options.verbose else logging.INFO

  setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), logging_level)
  global is_logger_setup
  is_logger_setup = True
  setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level)
  Logger.initialize_logger('resource_management', logging_level=logging_level)

  # use the host's locale for numeric formatting
  try:
    locale.setlocale(locale.LC_ALL, '')
  except locale.Error as ex:
    logger.warning("Cannot set locale for ambari-agent. Please check your systemwide locale settings. Failed due to: {0}.".format(str(ex)))

  default_cfg = {'agent': {'prefix': '/home/ambari'}}
  config.load(default_cfg)

  if (len(sys.argv) > 1) and sys.argv[1] == 'stop':
    stop_agent()

  if (len(sys.argv) > 2) and sys.argv[1] == 'reset':
    reset_agent(sys.argv)

  # Check for ambari configuration file.
  resolve_ambari_config()
  
  # Add syslog hanlder based on ambari config file
  add_syslog_handler(logger)

  # Starting data cleanup daemon
  data_cleaner = None
  if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0:
    data_cleaner = DataCleaner(config)
    data_cleaner.start()

  perform_prestart_checks(expected_hostname)

  # Starting ping port listener
  try:
    #This acts as a single process machine-wide lock (albeit incomplete, since
    # we still need an extra file to track the Agent PID)
    ping_port_listener = PingPortListener(config)
  except Exception as ex:
    err_message = "Failed to start ping port listener of: " + str(ex)
    logger.error(err_message)
    sys.stderr.write(err_message)
    sys.exit(1)
  ping_port_listener.start()

  update_log_level(config)

  if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY:
    daemonize()

  #
  # Iterate through the list of server hostnames and connect to the first active server
  #

  active_server = None
  server_hostnames = hostname.server_hostnames(config)

  connected = False
  stopped = False

  # Keep trying to connect to a server or bail out if ambari-agent was stopped
  while not connected and not stopped:
    for server_hostname in server_hostnames:
      try:
        server_ip = socket.gethostbyname(server_hostname)
        server_url = config.get_api_url(server_hostname)
        logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip)
      except socket.error:
        logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname)

      # Wait until MAX_RETRIES to see if server is reachable
      netutil = NetUtil(config, heartbeat_stop_callback)
      (retries, connected, stopped) = netutil.try_to_connect(server_url, MAX_RETRIES, logger)

      # if connected, launch controller
      if connected:
        logger.info('Connected to Ambari server %s', server_hostname)
        # Set the active server
        active_server = server_hostname
        # Launch Controller communication
        controller = Controller(config, server_hostname, heartbeat_stop_callback)
        controller.start()
        while controller.is_alive():
          time.sleep(0.1)

      #
#.........这里部分代码省略.........
开发者ID:maduhu,项目名称:HDP2.5-ambari,代码行数:103,代码来源:main.py

示例11: ArduinoCommunicator

# 需要导入模块: from Controller import Controller [as 别名]
# 或者: from Controller.Controller import start [as 别名]
    coms = ArduinoCommunicator(settings['COM'], settings['sensor'])
    # coms = DebugCommunicator(settings['COM'], settings['sensor'])

    app = QtWidgets.QApplication(sys.argv)
    app.setStyle(QtWidgets.QStyleFactory.create('Fusion'))
    MainWindow = QtWidgets.QMainWindow()
    ui = gui.Ui_MainWindow()
    ui.setupUi(MainWindow)
    control = Controller(settings, coms, script, MainWindow)

    update_list(control.program)

    control.pump_changed.connect(update_pump)
    control.temp_changed.connect(update_temp)
    control.program_changed.connect(update_list)
    control.sensors_changed.connect(update_sensors)

    ui.checkBox.stateChanged.connect(lambda x: control.pump_toggle(bool(x)))

    ui.upButton.clicked.connect(lambda x: control.shift_temp(0.5))
    ui.downButton.clicked.connect(lambda x: control.shift_temp(-0.5))
    ui.pauseButton.clicked.connect(lambda x: control.request_pause())



    control.start()

    MainWindow.show()
    sys.exit(app.exec_())
开发者ID:krismaz,项目名称:BrewLinker,代码行数:31,代码来源:SerialCom.py


注:本文中的Controller.Controller.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。