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


Python Lock.acquire方法代码示例

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


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

示例1: test_acquire_nowait

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [as 别名]
 def test_acquire_nowait(self):
   with temporary_file() as fd:
     def throw(pid):
       self.fail('Did not expect to wait for the 1st lock, held by %d' % pid)
     lock = Lock.acquire(fd.name, onwait=throw)
     try:
       def onwait(pid):
         self.assertEquals(os.getpid(), pid, "This process should hold the lock.")
         return False
       self.assertFalse(Lock.acquire(fd.name, onwait=onwait))
     finally:
       self.assertTrue(lock.release())
       self.assertFalse(lock.release())
开发者ID:BabyDuncan,项目名称:commons,代码行数:15,代码来源:lock_test.py

示例2: _run

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [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 acquire [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: acquire_lock

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [as 别名]
 def acquire_lock(self):
   """ Acquire the global lock for the root directory associated with this context. When
   a goal requires serialization, it will call this to acquire the lock.
   """
   def onwait(pid):
     print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr)
     return True
   if self._lock.is_unlocked():
     runfile = os.path.join(self._buildroot, '.pants.run')
     self._lock = Lock.acquire(runfile, onwait=onwait)
开发者ID:bonifaido,项目名称:commons,代码行数:12,代码来源:context.py

示例5: test_acquire_wait

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [as 别名]
  def test_acquire_wait(self):
    with temporary_dir() as path:
      lockfile = os.path.join(path, 'lock')

      childpid = os.fork()
      if childpid == 0:
        lock = Lock.acquire(lockfile)
        try:
          while True:
            time.sleep(1)
        except KeyboardInterrupt:
          lock.release()

      else:
        def childup():
          if not os.path.exists(lockfile):
            return False
          else:
            with open(lockfile) as fd:
              pid = fd.read().strip()
              return pid and pid == str(childpid)

        while not childup():
          time.sleep(0.1)

        # We should be blocked by the forked child lock owner
        def onwait(pid):
          self.assertEquals(childpid, pid)
          return False
        self.assertFalse(Lock.acquire(lockfile, onwait=onwait))

        # We should unblock after we 'kill' the forked child owner
        os.kill(childpid, signal.SIGINT)
        lock = Lock.acquire(lockfile)
        try:
          self.assertTrue(lock)
        finally:
          self.assertTrue(lock.release())
开发者ID:BabyDuncan,项目名称:commons,代码行数:40,代码来源:lock_test.py

示例6: _run

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [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

示例7: _run

# 需要导入模块: from twitter.common.dirutil import Lock [as 别名]
# 或者: from twitter.common.dirutil.Lock import acquire [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


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