Fix _UpdateStream race.
This commit is contained in:
parent
da77cb5870
commit
b9e4dd62e9
|
@ -166,7 +166,7 @@ class Channel(object):
|
||||||
Receive an object from the remote, or return ``None`` if `timeout` is
|
Receive an object from the remote, or return ``None`` if `timeout` is
|
||||||
reached.
|
reached.
|
||||||
"""
|
"""
|
||||||
LOG.debug('%r.Receive(%r)', self, timeout)
|
LOG.debug('%r.Receive(timeout=%r)', self, timeout)
|
||||||
try:
|
try:
|
||||||
data = self._queue.get(True, timeout)
|
data = self._queue.get(True, timeout)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
|
@ -394,11 +394,10 @@ class Stream(BasicStream):
|
||||||
Enqueue `obj` to `handle`, and tell the broker we have output.
|
Enqueue `obj` to `handle`, and tell the broker we have output.
|
||||||
"""
|
"""
|
||||||
LOG.debug('%r.Enqueue(%r, %r)', self, handle, obj)
|
LOG.debug('%r.Enqueue(%r, %r)', self, handle, obj)
|
||||||
encoded = self.Pickle((handle, obj))
|
|
||||||
msg = struct.pack('>L', len(encoded)) + encoded
|
|
||||||
|
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
try:
|
try:
|
||||||
|
encoded = self.Pickle((handle, obj))
|
||||||
|
msg = struct.pack('>L', len(encoded)) + encoded
|
||||||
self._whmac.update(msg)
|
self._whmac.update(msg)
|
||||||
self._output_buf += self._whmac.digest() + msg
|
self._output_buf += self._whmac.digest() + msg
|
||||||
finally:
|
finally:
|
||||||
|
@ -721,7 +720,7 @@ class Broker(object):
|
||||||
"""
|
"""
|
||||||
_waker = None
|
_waker = None
|
||||||
|
|
||||||
def __init__(self, log_level=logging.DEBUG):
|
def __init__(self, log_level=logging.INFO):
|
||||||
self.log_level = log_level
|
self.log_level = log_level
|
||||||
|
|
||||||
self._alive = True
|
self._alive = True
|
||||||
|
@ -743,6 +742,8 @@ class Broker(object):
|
||||||
|
|
||||||
def _UpdateStream(self, stream):
|
def _UpdateStream(self, stream):
|
||||||
LOG.debug('_UpdateStream(%r)', stream)
|
LOG.debug('_UpdateStream(%r)', stream)
|
||||||
|
self._lock.acquire()
|
||||||
|
try:
|
||||||
if stream.ReadMore() and stream.read_side.fileno():
|
if stream.ReadMore() and stream.read_side.fileno():
|
||||||
self._readers.add(stream.read_side)
|
self._readers.add(stream.read_side)
|
||||||
else:
|
else:
|
||||||
|
@ -752,6 +753,8 @@ class Broker(object):
|
||||||
self._writers.add(stream.write_side)
|
self._writers.add(stream.write_side)
|
||||||
else:
|
else:
|
||||||
self._writers.discard(stream.write_side)
|
self._writers.discard(stream.write_side)
|
||||||
|
finally:
|
||||||
|
self._lock.release()
|
||||||
|
|
||||||
def UpdateStream(self, stream):
|
def UpdateStream(self, stream):
|
||||||
LOG.debug('UpdateStream(%r)', stream)
|
LOG.debug('UpdateStream(%r)', stream)
|
||||||
|
@ -867,7 +870,7 @@ class ExternalContext(object):
|
||||||
klass.__module__ = 'econtext.core'
|
klass.__module__ = 'econtext.core'
|
||||||
|
|
||||||
def _SetupLogging(self, log_level):
|
def _SetupLogging(self, log_level):
|
||||||
logging.basicConfig(level=log_level)
|
logging.basicConfig(level=log_level, filename='slave.txt')
|
||||||
logging.getLogger('').handlers[0].formatter = Formatter(False)
|
logging.getLogger('').handlers[0].formatter = Formatter(False)
|
||||||
|
|
||||||
def _ReapFirstStage(self):
|
def _ReapFirstStage(self):
|
||||||
|
@ -921,6 +924,7 @@ class ExternalContext(object):
|
||||||
self._SetupMaster(key)
|
self._SetupMaster(key)
|
||||||
self._SetupImporter()
|
self._SetupImporter()
|
||||||
#self._SetupStdio()
|
#self._SetupStdio()
|
||||||
|
if 0:
|
||||||
fd = open('/dev/null', 'w')
|
fd = open('/dev/null', 'w')
|
||||||
os.dup2(fd.fileno(), 1)
|
os.dup2(fd.fileno(), 1)
|
||||||
os.dup2(fd.fileno(), 2)
|
os.dup2(fd.fileno(), 2)
|
||||||
|
|
Loading…
Reference in New Issue