1 |
commit: 43ec4d594870656fa2fb0ef169912e288d66101a |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Dec 31 22:24:04 2012 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Dec 31 22:24:04 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=43ec4d59 |
7 |
|
8 |
_LockThread: use thread-safe EventLoop.idle_add() |
9 |
|
10 |
--- |
11 |
pym/_emerge/AsynchronousLock.py | 43 +++++++------------------------------- |
12 |
1 files changed, 8 insertions(+), 35 deletions(-) |
13 |
|
14 |
diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py |
15 |
index 5bb9663..2de1acd 100644 |
16 |
--- a/pym/_emerge/AsynchronousLock.py |
17 |
+++ b/pym/_emerge/AsynchronousLock.py |
18 |
@@ -105,19 +105,9 @@ class _LockThread(AbstractPollTask): |
19 |
""" |
20 |
|
21 |
__slots__ = ('path',) + \ |
22 |
- ('_files', '_force_dummy', '_lock_obj', |
23 |
- '_thread', '_reg_id',) |
24 |
+ ('_force_dummy', '_lock_obj', '_thread',) |
25 |
|
26 |
def _start(self): |
27 |
- pr, pw = os.pipe() |
28 |
- self._files = {} |
29 |
- self._files['pipe_read'] = pr |
30 |
- self._files['pipe_write'] = pw |
31 |
- for f in self._files.values(): |
32 |
- fcntl.fcntl(f, fcntl.F_SETFL, |
33 |
- fcntl.fcntl(f, fcntl.F_GETFL) | os.O_NONBLOCK) |
34 |
- self._reg_id = self.scheduler.io_add_watch(self._files['pipe_read'], |
35 |
- self.scheduler.IO_IN, self._output_handler) |
36 |
self._registered = True |
37 |
threading_mod = threading |
38 |
if self._force_dummy: |
39 |
@@ -128,22 +118,14 @@ class _LockThread(AbstractPollTask): |
40 |
|
41 |
def _run_lock(self): |
42 |
self._lock_obj = lockfile(self.path, wantnewlockfile=True) |
43 |
- os.write(self._files['pipe_write'], b'\0') |
44 |
- |
45 |
- def _output_handler(self, f, event): |
46 |
- buf = None |
47 |
- if event & self.scheduler.IO_IN: |
48 |
- try: |
49 |
- buf = os.read(self._files['pipe_read'], self._bufsize) |
50 |
- except OSError as e: |
51 |
- if e.errno not in (errno.EAGAIN,): |
52 |
- raise |
53 |
- if buf: |
54 |
- self._unregister() |
55 |
- self.returncode = os.EX_OK |
56 |
- self.wait() |
57 |
+ # Thread-safe callback to EventLoop |
58 |
+ self.scheduler.idle_add(self._run_lock_cb) |
59 |
|
60 |
- return True |
61 |
+ def _run_lock_cb(self): |
62 |
+ self._unregister() |
63 |
+ self.returncode = os.EX_OK |
64 |
+ self.wait() |
65 |
+ return False |
66 |
|
67 |
def _cancel(self): |
68 |
# There's currently no way to force thread termination. |
69 |
@@ -164,15 +146,6 @@ class _LockThread(AbstractPollTask): |
70 |
self._thread.join() |
71 |
self._thread = None |
72 |
|
73 |
- if self._reg_id is not None: |
74 |
- self.scheduler.source_remove(self._reg_id) |
75 |
- self._reg_id = None |
76 |
- |
77 |
- if self._files is not None: |
78 |
- for f in self._files.values(): |
79 |
- os.close(f) |
80 |
- self._files = None |
81 |
- |
82 |
class _LockProcess(AbstractPollTask): |
83 |
""" |
84 |
This uses the portage.locks module to acquire a lock asynchronously, |