Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 524328 | Differences between
and this patch

Collapse All | Expand All

(-)a/bin/ebuild-ipc.py (-2 / +52 lines)
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._exit_cb, os.EX_OK)
83
84
	def _exit_cb(self, returncode):
85
		if self.returncode is None:
86
			self.returncode = returncode
87
			self._unregister()
88
			self.wait()
89
		return False
90
91
	def _cancel(self):
92
		# Do not join the thread, since it could block indefinitely
93
		# when opening/writing the fifo (as in bug #345455). Since
94
		# there's no way to force thread termination, simply allow
95
		# the daemon thread to terminate when the main thread
96
		# terminates. This class is only instantiated once, so there
97
		# will be no more than a single thread writing to self.fifo
98
		# during the life of the program (no chance of multiple
99
		# threads interfering with eachother).
100
		self.scheduler.timeout_add(0,
101
			self._exit_cb, -signal.SIGINT)
102
103
	def _unregister(self):
104
		self._registered = False
105
61
class EbuildIpc(object):
106
class EbuildIpc(object):
62
107
63
	# Timeout for each individual communication attempt (we retry
108
	# 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
255
		# considerations. This helps to avoid possible race conditions
211
		# from interference between timeouts and blocking IO operations.
256
		# from interference between timeouts and blocking IO operations.
212
		msg = portage.localization._('during write')
257
		msg = portage.localization._('during write')
258
		if threading is dummy_threading:
259
			# Try to avoid this fork due to possible
260
			# python deadlock (bug #524328).
261
			FifoWriter = FifoWriterFork
262
		else:
263
			FifoWriter = FifoWriterThread
213
		retval = self._run_writer(FifoWriter(buf=pickle.dumps(args),
264
		retval = self._run_writer(FifoWriter(buf=pickle.dumps(args),
214
			fifo=self.ipc_in_fifo, scheduler=global_event_loop()), msg)
265
			fifo=self.ipc_in_fifo, scheduler=global_event_loop()), msg)
215
266
216
- 

Return to bug 524328