當前位置: 首頁>>代碼示例>>Python>>正文


Python Lock.unlocked方法代碼示例

本文整理匯總了Python中twitter.common.dirutil.Lock.unlocked方法的典型用法代碼示例。如果您正苦於以下問題:Python Lock.unlocked方法的具體用法?Python Lock.unlocked怎麽用?Python Lock.unlocked使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twitter.common.dirutil.Lock的用法示例。


在下文中一共展示了Lock.unlocked方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: release_lock

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
 def release_lock(self):
   """Release the global lock if it's held.
   Returns True if the lock was held before this call.
   """
   if self._lock is Lock.unlocked():
     return False
   else:
     self._lock.release()
     self._lock = Lock.unlocked()
     return True
開發者ID:bonifaido,項目名稱:commons,代碼行數:12,代碼來源:context.py

示例2: _run

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
def _run():
  root_dir = get_buildroot()
  version = get_version()

  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES):
    _help(version, root_dir)

  command_class, command_args = _parse_command(root_dir, sys.argv[1:])

  parser = optparse.OptionParser(version = '%%prog %s' % version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION, action = 'store_true', dest = 'log_exit',
                    default = False, help = 'Log an exit message on success or failure')
  command = command_class(root_dir, parser, command_args)

  if command.serialized():
    def onwait(pid):
      print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr)
      return True
    runfile = os.path.join(root_dir, '.pants.run')
    lock = Lock.acquire(runfile, onwait=onwait)
  else:
    lock = Lock.unlocked()
  try:
    result = command.run(lock)
    _do_exit(result)
  finally:
    lock.release()
開發者ID:avadh,項目名稱:commons,代碼行數:33,代碼來源:pants_exe.py

示例3: _run

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
def _run():
  version = get_version()
  if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION:
    _do_exit(version)

  root_dir = get_buildroot()
  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES):
    _help(version, root_dir)

  command_class, command_args = _parse_command(root_dir, sys.argv[1:])

  parser = optparse.OptionParser(version=version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION,
                    action='store_true',
                    default=False,
                    dest='log_exit',
                    help = 'Log an exit message on success or failure.')

  config = Config.load()
  run_tracker = RunTracker(config)
  report = initial_reporting(config, run_tracker)
  run_tracker.start(report)

  url = run_tracker.run_info.get_info('report_url')
  if url:
    run_tracker.log(Report.INFO, 'See a report at: %s' % url)
  else:
    run_tracker.log(Report.INFO, '(To run a reporting server: ./pants server)')

  command = command_class(run_tracker, root_dir, parser, command_args)
  try:
    if command.serialized():
      def onwait(pid):
        print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr)
        return True
      runfile = os.path.join(root_dir, '.pants.run')
      lock = Lock.acquire(runfile, onwait=onwait)
    else:
      lock = Lock.unlocked()
    try:
      result = command.run(lock)
      _do_exit(result)
    except KeyboardInterrupt:
      command.cleanup()
      raise
    finally:
      lock.release()
  finally:
    run_tracker.end()
    # Must kill nailguns only after run_tracker.end() is called, because there may still
    # be pending background work that needs a nailgun.
    if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \
        or config.get('nailgun', 'autokill', default=False):
      NailgunTask.killall(None)
開發者ID:alfss,項目名稱:commons,代碼行數:60,代碼來源:pants_exe.py

示例4: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, target_roots, lock=None, log=None):
    self._config = config
    self._options = options
    self._lock = lock or Lock.unlocked()
    self._log = log or Context.Log()
    self._state = {}
    self._products = Products()

    self.replace_targets(target_roots)
開發者ID:JoeEnnever,項目名稱:commons,代碼行數:11,代碼來源:context.py

示例5: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, target_roots, lock=Lock.unlocked(), log=None, timer=None):
    self._config = config
    self._options = options
    self._lock = lock
    self._log = log or Context.Log()
    self._state = {}
    self._products = Products()
    self._buildroot = get_buildroot()
    self.timer = timer

    self.replace_targets(target_roots)
開發者ID:SeungEun,項目名稱:commons,代碼行數:13,代碼來源:context.py

示例6: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, run_tracker, target_roots, requested_goals=None,
               lock=Lock.unlocked(), log=None, target_base=None):
    self._config = config
    self._options = options
    self.run_tracker = run_tracker
    self._lock = lock
    self._log = log or Context.Log(run_tracker)
    self._target_base = target_base or Target
    self._state = {}
    self._products = Products()
    self._buildroot = get_buildroot()
    self.requested_goals = requested_goals or []

    self.replace_targets(target_roots)
開發者ID:davearata,項目名稱:twitter-commons,代碼行數:16,代碼來源:context.py

示例7: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, run_tracker, target_roots, requested_goals=None,
               lock=None, log=None):
    self._config = config
    self._options = options
    self.run_tracker = run_tracker
    self._lock = lock or Lock.unlocked()
    self._log = log or Context.Log(run_tracker)
    self._state = {}
    self._products = Products()
    self._buildroot = get_buildroot()
    self._java_home = None  # Computed lazily.
    self.requested_goals = requested_goals or []

    self.replace_targets(target_roots)
開發者ID:ssalevan,項目名稱:commons,代碼行數:16,代碼來源:context.py

示例8: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, run_tracker, target_roots, requested_goals=None,
               lock=None, log=None, target_base=None, build_graph=None, build_file_parser=None):
    self._config = config
    self._options = options
    self.build_graph = build_graph
    self.build_file_parser = build_file_parser
    self.run_tracker = run_tracker
    self._lock = lock or Lock.unlocked()
    self._log = log or Context.Log(run_tracker)
    self._target_base = target_base or Target

    self._products = Products()
    self._buildroot = get_buildroot()
    self._java_sysprops = None  # Computed lazily.
    self.requested_goals = requested_goals or []

    self.replace_targets(target_roots)
開發者ID:igmor,項目名稱:pants,代碼行數:19,代碼來源:context.py

示例9: __init__

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
  def __init__(self, config, options, run_tracker, target_roots, requested_goals=None,
               lock=None, log=None, target_base=None, build_graph=None, build_file_parser=None,
               address_mapper=None, console_outstream=None, scm=None, workspace=None):
    self._config = config
    self._options = options
    self.build_graph = build_graph
    self.build_file_parser = build_file_parser
    self.address_mapper = address_mapper
    self.run_tracker = run_tracker
    self._lock = lock or Lock.unlocked()
    self._log = log or Context.Log(run_tracker)
    self._target_base = target_base or Target
    self._products = Products()
    self._buildroot = get_buildroot()
    self._java_sysprops = None  # Computed lazily.
    self.requested_goals = requested_goals or []
    self._console_outstream = console_outstream or sys.stdout
    self._scm = scm or get_scm()
    self._workspace = workspace or (ScmWorkspace(self._scm) if self._scm else None)

    self.replace_targets(target_roots)
開發者ID:jcoveney,項目名稱:pants,代碼行數:23,代碼來源:context.py

示例10: _run

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
def _run():
  """
  To add additional paths to sys.path, add a block to the config similar to the following:
  [main]
  roots: ['src/python/twitter/pants_internal/test/',]
  """
  version = get_version()
  if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION:
    _do_exit(version)

  root_dir = get_buildroot()
  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES):
    _help(version, root_dir)

  command_class, command_args = _parse_command(root_dir, sys.argv[1:])

  parser = optparse.OptionParser(version=version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION,
                    action='store_true',
                    default=False,
                    dest='log_exit',
                    help = 'Log an exit message on success or failure.')

  config = Config.load()

  # TODO: This can be replaced once extensions are enabled with
  # https://github.com/pantsbuild/pants/issues/5
  roots = config.getlist('parse', 'roots', default=[])
  sys.path.extend(map(lambda root: os.path.join(root_dir, root), roots))

  # XXX(wickman) This should be in the command goal, not un pants_exe.py!
  run_tracker = RunTracker.from_config(config)
  report = initial_reporting(config, run_tracker)
  run_tracker.start(report)

  url = run_tracker.run_info.get_info('report_url')
  if url:
    run_tracker.log(Report.INFO, 'See a report at: %s' % url)
  else:
    run_tracker.log(Report.INFO, '(To run a reporting server: ./pants server)')

  command = command_class(run_tracker, root_dir, parser, command_args)
  try:
    if command.serialized():
      def onwait(pid):
        print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr)
        return True
      runfile = os.path.join(root_dir, '.pants.run')
      lock = Lock.acquire(runfile, onwait=onwait)
    else:
      lock = Lock.unlocked()
    try:
      result = command.run(lock)
      _do_exit(result)
    except KeyboardInterrupt:
      command.cleanup()
      raise
    finally:
      lock.release()
  finally:
    run_tracker.end()
    # Must kill nailguns only after run_tracker.end() is called, because there may still
    # be pending background work that needs a nailgun.
    if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \
        or config.get('nailgun', 'autokill', default=False):
      NailgunTask.killall(None)
開發者ID:FernandoG26,項目名稱:commons,代碼行數:72,代碼來源:pants_exe.py

示例11: _run

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
def _run():
  # Place the registration of the unhandled exception hook as early as possible in the code.
  sys.excepthook = _unhandled_exception_hook

  """
  To add additional paths to sys.path, add a block to the config similar to the following:
  [main]
  roots: ['src/python/pants_internal/test/',]
  """

  logging.basicConfig()
  version = pants_version()
  if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION:
    _do_exit(msg=version, out=sys.stdout)

  root_dir = get_buildroot()
  if not os.path.exists(root_dir):
    _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir)

  if len(sys.argv) < 2:
    argv = ['goal']
  else:
    argv = sys.argv[1:]
  # Hack to force ./pants -h etc. to redirect to goal.
  if argv[0] != 'goal' and set(['-h', '--help', 'help']).intersection(argv):
    argv = ['goal'] + argv

  parser = optparse.OptionParser(add_help_option=False, version=version)
  RcFile.install_disable_rc_option(parser)
  parser.add_option(_LOG_EXIT_OPTION,
                    action='store_true',
                    default=False,
                    dest='log_exit',
                    help='Log an exit message on success or failure.')

  config = Config.load()

  # XXX(wickman) This should be in the command goal, not in pants_exe.py!
  run_tracker = RunTracker.from_config(config)
  report = initial_reporting(config, run_tracker)
  run_tracker.start(report)

  url = run_tracker.run_info.get_info('report_url')
  if url:
    run_tracker.log(Report.INFO, 'See a report at: %s' % url)
  else:
    run_tracker.log(Report.INFO, '(To run a reporting server: ./pants goal server)')

  backend_packages = config.getlist('backends', 'packages')
  build_configuration = load_build_configuration_from_source(additional_backends=backend_packages)
  build_file_parser = BuildFileParser(build_configuration=build_configuration,
                                      root_dir=root_dir,
                                      run_tracker=run_tracker)
  address_mapper = BuildFileAddressMapper(build_file_parser)
  build_graph = BuildGraph(run_tracker=run_tracker, address_mapper=address_mapper)

  command_class, command_args = _parse_command(root_dir, argv)
  command = command_class(run_tracker,
                          root_dir,
                          parser,
                          command_args,
                          build_file_parser,
                          address_mapper,
                          build_graph)
  try:
    if command.serialized():
      def onwait(pid):
        process = psutil.Process(pid)
        print('Waiting on pants process %d (%s) to complete' %
              (pid, ' '.join(process.cmdline)), file=sys.stderr)
        return True
      runfile = os.path.join(root_dir, '.pants.run')
      lock = Lock.acquire(runfile, onwait=onwait)
    else:
      lock = Lock.unlocked()
    try:
      result = command.run(lock)
      if result:
        run_tracker.set_root_outcome(WorkUnit.FAILURE)
      _do_exit(result)
    except KeyboardInterrupt:
      command.cleanup()
      raise
    except Exception:
      run_tracker.set_root_outcome(WorkUnit.FAILURE)
      raise
    finally:
      lock.release()
  finally:
    run_tracker.end()
    # Must kill nailguns only after run_tracker.end() is called, because there may still
    # be pending background work that needs a nailgun.
    if (hasattr(command.old_options, 'cleanup_nailguns') and command.old_options.cleanup_nailguns) \
        or config.get('nailgun', 'autokill', default=False):
      NailgunTask.killall(None)
開發者ID:ankurgarg1986,項目名稱:pants,代碼行數:97,代碼來源:pants_exe.py

示例12: test_unlocked

# 需要導入模塊: from twitter.common.dirutil import Lock [as 別名]
# 或者: from twitter.common.dirutil.Lock import unlocked [as 別名]
 def test_unlocked(self):
   lock1 = Lock.unlocked()
   lock2 = Lock.unlocked()
   self.assertFalse(lock1.release())
   self.assertFalse(lock1.release())
   self.assertFalse(lock2.release())
開發者ID:BabyDuncan,項目名稱:commons,代碼行數:8,代碼來源:lock_test.py


注:本文中的twitter.common.dirutil.Lock.unlocked方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。