Python imp.lock_held() Examples
The following are 30
code examples of imp.lock_held().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
imp
, or try the search function
.
Example #1
Source File: test_threaded_import.py From ironpython2 with Apache License 2.0 | 6 votes |
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()
Example #2
Source File: test_threaded_import.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #3
Source File: test_threaded_import.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
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()
Example #4
Source File: test_threaded_import.py From BinderFilter with MIT License | 6 votes |
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()
Example #5
Source File: test_threaded_import.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
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()
Example #6
Source File: test_threaded_import.py From oss-ftp with MIT License | 6 votes |
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()
Example #7
Source File: test_threaded_import.py From medicare-demo with Apache License 2.0 | 6 votes |
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()
Example #8
Source File: test_imp.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #9
Source File: test_imp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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")
Example #10
Source File: test_imp.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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")
Example #11
Source File: state.py From squadron with MIT License | 5 votes |
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
Example #12
Source File: __init__.py From pypreprocessor with MIT License | 5 votes |
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
Example #13
Source File: test_imp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #14
Source File: test_imp.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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")
Example #15
Source File: test_socketserver.py From medicare-demo with Apache License 2.0 | 5 votes |
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()
Example #16
Source File: test_imp.py From medicare-demo with Apache License 2.0 | 5 votes |
def verify_lock_state(expected): if imp.lock_held() != expected: raise TestFailed("expected imp.lock_held() to be %r" % expected)
Example #17
Source File: test_imp.py From medicare-demo with Apache License 2.0 | 5 votes |
def testLock(): 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() verify_lock_state(lock_held_at_start) for i in range(LOOPS): imp.acquire_lock() verify_lock_state(True) for i in range(LOOPS): imp.release_lock() # The original state should be restored now. verify_lock_state(lock_held_at_start) if not lock_held_at_start: try: imp.release_lock() except RuntimeError: pass else: raise TestFailed("release_lock() without lock should raise " "RuntimeError")
Example #18
Source File: test_socketserver.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: test_imp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #20
Source File: test_imp.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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")
Example #21
Source File: test_socketserver.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: test_imp.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #23
Source File: test_imp.py From ironpython3 with Apache License 2.0 | 5 votes |
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()
Example #24
Source File: test_socketserver.py From ironpython2 with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #26
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
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")
Example #27
Source File: test_imp.py From ironpython2 with Apache License 2.0 | 5 votes |
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()
Example #28
Source File: test_socketserver.py From BinderFilter with MIT License | 5 votes |
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)
Example #29
Source File: test_imp.py From BinderFilter with MIT License | 5 votes |
def verify_lock_state(self, expected): self.assertEqual(imp.lock_held(), expected, "expected imp.lock_held() to be %r" % expected)
Example #30
Source File: test_imp.py From BinderFilter with MIT License | 5 votes |
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")