Add darwin-specific shared mem file open and close in RemoteGraphicsView.py to account for lack of mremap on platform.

This commit is contained in:
Chadwick Boulay 2016-03-29 18:24:16 -04:00
parent 0ac914fae7
commit a8d3aad97a

View File

@ -77,6 +77,10 @@ class RemoteGraphicsView(QtGui.QWidget):
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
self.shmtag = newfile ## on windows, we create a new tag for every resize self.shmtag = newfile ## on windows, we create a new tag for every resize
self.shm = mmap.mmap(-1, size, self.shmtag) ## can't use tmpfile on windows because the file can only be opened once. self.shm = mmap.mmap(-1, size, self.shmtag) ## can't use tmpfile on windows because the file can only be opened once.
elif sys.platform == 'darwin':
self.shmFile.close()
self.shmFile = open(self._view.shmFileName(), 'r')
self.shm = mmap.mmap(self.shmFile.fileno(), size, mmap.MAP_SHARED, mmap.PROT_READ)
else: else:
self.shm = mmap.mmap(self.shmFile.fileno(), size, mmap.MAP_SHARED, mmap.PROT_READ) self.shm = mmap.mmap(self.shmFile.fileno(), size, mmap.MAP_SHARED, mmap.PROT_READ)
self.shm.seek(0) self.shm.seek(0)
@ -193,6 +197,13 @@ class Renderer(GraphicsView):
## it also says (sometimes) 'access is denied' if we try to reuse the tag. ## it also says (sometimes) 'access is denied' if we try to reuse the tag.
self.shmtag = "pyqtgraph_shmem_" + ''.join([chr((random.getrandbits(20)%25) + 97) for i in range(20)]) self.shmtag = "pyqtgraph_shmem_" + ''.join([chr((random.getrandbits(20)%25) + 97) for i in range(20)])
self.shm = mmap.mmap(-1, size, self.shmtag) self.shm = mmap.mmap(-1, size, self.shmtag)
elif sys.platform == 'darwin':
self.shm.close()
self.shmFile.close()
self.shmFile = tempfile.NamedTemporaryFile(prefix='pyqtgraph_shmem_')
self.shmFile.write(b'\x00' * (size + 1))
self.shmFile.flush()
self.shm = mmap.mmap(self.shmFile.fileno(), size, mmap.MAP_SHARED, mmap.PROT_WRITE)
else: else:
self.shm.resize(size) self.shm.resize(size)