aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2018-04-21 01:47:07 -0700
committerZac Medico <zmedico@gentoo.org>2018-04-22 11:30:54 -0700
commita68bf18050580eaf60bc0447558c63346b985049 (patch)
treed48a5bf6fd0860bbb887a920421108d55c0ad170
parentEbuildBuildDir: remove synchronous lock method (bug 614112) (diff)
downloadportage-a68bf18050580eaf60bc0447558c63346b985049.tar.gz
portage-a68bf18050580eaf60bc0447558c63346b985049.tar.bz2
portage-a68bf18050580eaf60bc0447558c63346b985049.zip
AsynchronousLock: remove synchronous unlock method (bug 614108)
The synchronous unlock method can trigger event loop recursion if the event loop is already running, which is incompatible with asyncio's default event loop. Therefore, migrate the last consumers to use the async_unlock method, and remove the synchronous unlock method. Bug: https://bugs.gentoo.org/614108 Bug: https://bugs.gentoo.org/649588
-rw-r--r--pym/_emerge/AsynchronousLock.py32
-rw-r--r--pym/portage/tests/locks/test_asynchronous_lock.py22
2 files changed, 7 insertions, 47 deletions
diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py
index fb0c2b30d..78ab37ecb 100644
--- a/pym/_emerge/AsynchronousLock.py
+++ b/pym/_emerge/AsynchronousLock.py
@@ -87,20 +87,6 @@ class AsynchronousLock(AsynchronousTask):
self.returncode = self._imp.wait()
return self.returncode
- def unlock(self):
- """
- This method is deprecated in favor of async_unlock, since waiting
- for the child process to respond can trigger event loop recursion
- which is incompatible with asyncio.
- """
- if self._imp is None:
- raise AssertionError('not locked')
- if isinstance(self._imp, (_LockProcess, _LockThread)):
- self._imp.unlock()
- else:
- unlockfile(self._imp)
- self._imp = None
-
def async_unlock(self):
"""
Release the lock asynchronously. Release notification is available
@@ -162,14 +148,6 @@ class _LockThread(AbstractPollTask):
# There's currently no way to force thread termination.
pass
- def unlock(self):
- """
- This method is deprecated in favor of async_unlock, for compatibility
- with _LockProcess.
- """
- self._unlock()
- self._unlock_future.set_result(None)
-
def _unlock(self):
if self._lock_obj is None:
raise AssertionError('not locked')
@@ -327,16 +305,6 @@ class _LockProcess(AbstractPollTask):
else:
os.close(pipe_in)
- def unlock(self):
- """
- This method is deprecated in favor of async_unlock, since waiting
- for the child process to respond can trigger event loop recursion
- which is incompatible with asyncio.
- """
- self._unlock()
- self._proc.wait()
- self._proc = None
-
def _unlock(self):
if self._proc is None:
raise AssertionError('not locked')
diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py
index 6493b6da6..338d91e09 100644
--- a/pym/portage/tests/locks/test_asynchronous_lock.py
+++ b/pym/portage/tests/locks/test_asynchronous_lock.py
@@ -1,7 +1,6 @@
# Copyright 2010-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-import itertools
import signal
import tempfile
@@ -23,8 +22,7 @@ class AsynchronousLockTestCase(TestCase):
tempdir = tempfile.mkdtemp()
try:
path = os.path.join(tempdir, 'lock_me')
- for force_async, async_unlock in itertools.product(
- (True, False), repeat=2):
+ for force_async in (True, False):
for force_dummy in ((False,) if dummy_threading is None
else (True, False)):
async_lock = AsynchronousLock(path=path,
@@ -34,10 +32,7 @@ class AsynchronousLockTestCase(TestCase):
async_lock.start()
self.assertEqual(async_lock.wait(), os.EX_OK)
self.assertEqual(async_lock.returncode, os.EX_OK)
- if async_unlock:
- scheduler.run_until_complete(async_lock.async_unlock())
- else:
- async_lock.unlock()
+ scheduler.run_until_complete(async_lock.async_unlock())
async_lock = AsynchronousLock(path=path,
scheduler=scheduler, _force_async=force_async,
@@ -45,10 +40,7 @@ class AsynchronousLockTestCase(TestCase):
async_lock.start()
self.assertEqual(async_lock.wait(), os.EX_OK)
self.assertEqual(async_lock.returncode, os.EX_OK)
- if async_unlock:
- scheduler.run_until_complete(async_lock.async_unlock())
- else:
- async_lock.unlock()
+ scheduler.run_until_complete(async_lock.async_unlock())
finally:
shutil.rmtree(tempdir)
@@ -86,10 +78,10 @@ class AsynchronousLockTestCase(TestCase):
self.assertEqual(lock2.poll(), None)
self.assertEqual(lock2.returncode, None)
- lock1.unlock()
+ scheduler.run_until_complete(lock1.async_unlock())
self.assertEqual(lock2.wait(), os.EX_OK)
self.assertEqual(lock2.returncode, os.EX_OK)
- lock2.unlock()
+ scheduler.run_until_complete(lock2.async_unlock())
finally:
shutil.rmtree(tempdir)
@@ -127,7 +119,7 @@ class AsynchronousLockTestCase(TestCase):
self.assertEqual(lock2.wait() == os.EX_OK, False)
self.assertEqual(lock2.returncode == os.EX_OK, False)
self.assertEqual(lock2.returncode is None, False)
- lock1.unlock()
+ scheduler.run_until_complete(lock1.async_unlock())
finally:
shutil.rmtree(tempdir)
@@ -171,7 +163,7 @@ class AsynchronousLockTestCase(TestCase):
self.assertEqual(lock2.wait() == os.EX_OK, False)
self.assertEqual(lock2.returncode == os.EX_OK, False)
self.assertEqual(lock2.returncode is None, False)
- lock1.unlock()
+ scheduler.run_until_complete(lock1.async_unlock())
finally:
shutil.rmtree(tempdir)