本文整理汇总了Python中twitter.common.dirutil.Lock类的典型用法代码示例。如果您正苦于以下问题:Python Lock类的具体用法?Python Lock怎么用?Python Lock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _run
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,代码行数:31,代码来源:pants_exe.py
示例2: _run
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,代码行数:58,代码来源:pants_exe.py
示例3: release_lock
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,代码行数:10,代码来源:context.py
示例4: test_acquire_nowait
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,代码行数:13,代码来源:lock_test.py
示例5: __init__
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,代码行数:9,代码来源:context.py
示例6: acquire_lock
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,代码行数:10,代码来源:context.py
示例7: __init__
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,代码行数:11,代码来源:context.py
示例8: test_acquire_wait
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,代码行数:38,代码来源:lock_test.py
示例9: __init__
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,代码行数:14,代码来源:context.py
示例10: __init__
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,代码行数:14,代码来源:context.py
示例11: __init__
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,代码行数:17,代码来源:context.py
示例12: __init__
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,代码行数:21,代码来源:context.py
示例13: _run
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,代码行数:70,代码来源:pants_exe.py
示例14: _run
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,代码行数:95,代码来源:pants_exe.py
示例15: test_unlocked
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,代码行数:6,代码来源:lock_test.py
注:本文中的twitter.common.dirutil.Lock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论