本文整理匯總了Python中imp.lock_held方法的典型用法代碼示例。如果您正苦於以下問題:Python imp.lock_held方法的具體用法?Python imp.lock_held怎麽用?Python imp.lock_held使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類imp
的用法示例。
在下文中一共展示了imp.lock_held方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_main
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def test_main(): # magic name! see above
global N, done
import imp
if imp.lock_held():
# This triggers on, e.g., from test import autotest.
raise unittest.SkipTest("can't run when import lock is held")
done.acquire()
for N in (20, 50) * 3:
if verbose:
print "Trying", N, "threads ...",
for i in range(N):
thread.start_new_thread(task, ())
done.acquire()
if verbose:
print "OK."
done.release()
test_import_hangers()
示例2: test_main
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def test_main(): # magic name! see above
global N, done
import imp
if imp.lock_held():
# This triggers on, e.g., from test import autotest.
raise TestSkipped("can't run when import lock is held")
done.acquire()
for N in (20, 50) * 3:
if verbose:
print "Trying", N, "threads ...",
for i in range(N):
thread.start_new_thread(task, ())
done.acquire()
if verbose:
print "OK."
done.release()
test_import_hangers()
示例3: test_main
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def test_main():
if imp.lock_held():
# If the import lock is held, the threads will hang
raise unittest.SkipTest("can't run when import lock is held")
test.test_support.run_unittest(SocketServerTest)
示例4: verify_lock_state
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def verify_lock_state(self, expected):
self.assertEqual(imp.lock_held(), expected,
"expected imp.lock_held() to be %r" % expected)
示例5: testLock
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def testLock(self):
LOOPS = 50
# The import lock may already be held, e.g. if the test suite is run
# via "import test.autotest".
lock_held_at_start = imp.lock_held()
self.verify_lock_state(lock_held_at_start)
for i in range(LOOPS):
imp.acquire_lock()
self.verify_lock_state(True)
for i in range(LOOPS):
imp.release_lock()
# The original state should be restored now.
self.verify_lock_state(lock_held_at_start)
if not lock_held_at_start:
try:
imp.release_lock()
except RuntimeError:
pass
else:
self.fail("release_lock() without lock should raise "
"RuntimeError")
示例6: test_lock
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def test_lock(self):
i=0
while i<5:
i+=1
if not imp.lock_held():
self.assertRaises(RuntimeError,imp.release_lock)
imp.acquire_lock()
else:
imp.release_lock()
示例7: apply
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def apply(self, library_name, inputhash, dry_run = False):
"""
Changes the state of the system according to what the module
specified does
Keyword arguments:
library_name -- the python module to load
inputhash -- the list of dictionaries of config for the library
dry_run -- whether or not to actually change the system
"""
log.debug('entering state.apply %s', [library_name, inputhash, dry_run])
if library_name not in sys.modules:
try:
imp.acquire_lock()
mod = imp.find_module(library_name, self.libraries)
imp.load_module(library_name, *mod)
except ImportError:
log.exception("Couldn't find module %s in dirs %s", library_name, self.libraries)
raise
finally:
if imp.lock_held():
imp.release_lock()
log.debug('loading library: %s', library_name)
library = importlib.import_module(library_name)
schema = library.schema()
for item in inputhash:
jsonschema.validate(item, schema)
failed = library.verify(inputhashes=inputhash, log=log)
log.debug('dry run: %s', dry_run)
if not dry_run:
log.debug('applying state...')
library.apply(inputhashes=failed, log=log)
failed = library.verify(inputhashes=inputhash, log=log)
if len(failed) > 0:
log.error("Failed for good on {}".format(failed))
log.debug('Leaving state.apply %s', failed)
return failed
示例8: post_process
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def post_process(self):
try:
# set file name
if self.output == '':
self.output = self.input[0:-len(self.input.split('.')[-1])-1]+'_out.'+self.input.split('.')[-1]
# open file for output
output_file = io.open(self.output, 'w', encoding=self.writeEncoding)
# write post-processed code to file
output_file.write(self.__outputBuffer)
finally:
output_file.close()
if self.run:
# if this module is loaded as a library override the import
if imp.lock_held() is True:
self.override_import()
else:
self.on_the_fly()
if not self.save:
# remove tmp file
if os.path.exists(self.output):
os.remove(self.output)
if not self.resume:
# break execution so python doesn't
# run the rest of the pre-processed code
sys.exit(0)
# postprocessor - override an import
示例9: test_main
# 需要導入模塊: import imp [as 別名]
# 或者: from imp import lock_held [as 別名]
def test_main():
import imp
if imp.lock_held():
# If the import lock is held, the threads will hang.
raise TestSkipped("can't run when import lock is held")
try:
testall()
finally:
cleanup()
reap_children()