Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

OpenBSD fixes.

This might also fix some niggling Linux bugs that are rare and almost
impossible to reproduce but I can't tell... because I couldn't reproduce
them. However, on OpenBSD these problems show up regularly.

Signed-off-by: Jack Miller <jack@codezen.org>
  • Loading branch information...
commit e5a4b15b0ddcab49699ab2293d560966fd9af810 1 parent 9b313e5
@themoken authored
Showing with 40 additions and 10 deletions.
  1. +40 −10 canto/process.py
View
50 canto/process.py
@@ -106,6 +106,7 @@
from cPickle import dumps, loads
import select
import signal
+import errno
import time
import sys
import os
@@ -122,17 +123,41 @@ def __init__(self):
self.thread = None
self.alive = True
+ self.frag = ""
+
+ def _try_parse(self):
+ if "\0" in self.frag:
+ idx = self.frag.index("\0")
+ s, self.frag = self.frag[:idx], self.frag[idx+1:]
+ return loads(s)
+ return None
def get(self, block=True, timeout=None):
+
+ # Parse a message out of the remaining fragment.
+ r = self._try_parse()
+ if r:
+ return r
+
ready = self.poll.poll(timeout)
- for fd, event in ready:
- l = os.read(self.recvpipe, 1)
- while l[-1] != " ":
- l += os.read(self.recvpipe, 1)
- l = int(l)
+ if not ready:
+ raise Exception
+
+ while True:
+ try:
+ self.frag += os.read(self.recvpipe, 1024)
+ r = self._try_parse()
+ if r:
+ return r
+ except OSError, e:
+ if e.errno == errno.EINTR:
+ continue
+ raise
+
+ if block and timeout == None:
+ continue
+ break
- s = os.read(self.recvpipe, l)
- return loads(s)
raise Exception
def feed_pipe(self):
@@ -145,9 +170,14 @@ def feed_pipe(self):
self.objlist = self.objlist[1:]
self.objlock.release()
- s = dumps(obj)
- l = len(s)
- os.write(self.sendpipe, "%d %s" % (l, s))
+ s = dumps(obj) + "\0"
+ while s:
+ try:
+ written = os.write(self.sendpipe, s)
+ s = s[written:]
+ except OSError, e:
+ if e.errno != errno.EINTR:
+ raise
def put(self, obj):
if not self.thread:
Please sign in to comment.
Something went wrong with that request. Please try again.