Lines 5-10
Link Here
|
5 |
# This is a helper which ebuild processes can use |
5 |
# This is a helper which ebuild processes can use |
6 |
# to communicate with portage's main python process. |
6 |
# to communicate with portage's main python process. |
7 |
|
7 |
|
|
|
8 |
import dummy_threading |
8 |
import logging |
9 |
import logging |
9 |
import os |
10 |
import os |
10 |
import pickle |
11 |
import pickle |
Lines 13-18
import signal
Link Here
|
13 |
import sys |
14 |
import sys |
14 |
import time |
15 |
import time |
15 |
|
16 |
|
|
|
17 |
try: |
18 |
import threading |
19 |
except ImportError: |
20 |
threading = dummy_threading |
21 |
|
16 |
def debug_signal(signum, frame): |
22 |
def debug_signal(signum, frame): |
17 |
import pdb |
23 |
import pdb |
18 |
pdb.set_trace() |
24 |
pdb.set_trace() |
Lines 46-54
portage._disable_legacy_globals()
Link Here
|
46 |
|
52 |
|
47 |
from portage.util._async.ForkProcess import ForkProcess |
53 |
from portage.util._async.ForkProcess import ForkProcess |
48 |
from portage.util._eventloop.global_event_loop import global_event_loop |
54 |
from portage.util._eventloop.global_event_loop import global_event_loop |
|
|
55 |
from _emerge.AbstractPollTask import AbstractPollTask |
49 |
from _emerge.PipeReader import PipeReader |
56 |
from _emerge.PipeReader import PipeReader |
50 |
|
57 |
|
51 |
class FifoWriter(ForkProcess): |
58 |
class FifoWriterFork(ForkProcess): |
52 |
|
59 |
|
53 |
__slots__ = ('buf', 'fifo',) |
60 |
__slots__ = ('buf', 'fifo',) |
54 |
|
61 |
|
Lines 58-63
class FifoWriter(ForkProcess):
Link Here
|
58 |
f.write(self.buf) |
65 |
f.write(self.buf) |
59 |
return os.EX_OK |
66 |
return os.EX_OK |
60 |
|
67 |
|
|
|
68 |
class FifoWriterThread(AbstractPollTask): |
69 |
|
70 |
__slots__ = ('buf', 'fifo', '_thread',) |
71 |
|
72 |
def _start(self): |
73 |
self._registered = True |
74 |
self._thread = threading.Thread(target=self._write_fifo) |
75 |
self._thread.daemon = True |
76 |
self._thread.start() |
77 |
|
78 |
def _write_fifo(self): |
79 |
with open(self.fifo, 'wb', 0) as f: |
80 |
f.write(self.buf) |
81 |
# Thread-safe callback to EventLoop |
82 |
self.scheduler.timeout_add(0, self._write_fifo_cb, os.EX_OK) |
83 |
|
84 |
def _write_fifo_cb(self, returncode): |
85 |
self.returncode = returncode |
86 |
self._unregister() |
87 |
self.wait() |
88 |
return False |
89 |
|
90 |
def _cancel(self): |
91 |
# There's currently no way to force thread termination. |
92 |
pass |
93 |
|
94 |
def _unregister(self): |
95 |
self._registered = False |
96 |
if self._thread is not None: |
97 |
self._thread.join() |
98 |
self._thread = None |
99 |
|
61 |
class EbuildIpc(object): |
100 |
class EbuildIpc(object): |
62 |
|
101 |
|
63 |
# Timeout for each individual communication attempt (we retry |
102 |
# Timeout for each individual communication attempt (we retry |
Lines 210-215
class EbuildIpc(object):
Link Here
|
210 |
# considerations. This helps to avoid possible race conditions |
249 |
# considerations. This helps to avoid possible race conditions |
211 |
# from interference between timeouts and blocking IO operations. |
250 |
# from interference between timeouts and blocking IO operations. |
212 |
msg = portage.localization._('during write') |
251 |
msg = portage.localization._('during write') |
|
|
252 |
if threading is dummy_threading: |
253 |
# Try to avoid this fork due to possible |
254 |
# python deadlock (bug #524328). |
255 |
FifoWriter = FifoWriterFork |
256 |
else: |
257 |
FifoWriter = FifoWriterThread |
213 |
retval = self._run_writer(FifoWriter(buf=pickle.dumps(args), |
258 |
retval = self._run_writer(FifoWriter(buf=pickle.dumps(args), |
214 |
fifo=self.ipc_in_fifo, scheduler=global_event_loop()), msg) |
259 |
fifo=self.ipc_in_fifo, scheduler=global_event_loop()), msg) |
215 |
|
260 |
|
216 |
- |
|
|