Merge pull request #304 from cboulay/osx_mremap

OSX RemoteGrahpics.py: Add shared mem file open and close to get around no mremap.
This commit is contained in:
Luke Campagnola 2016-04-21 00:35:31 -07:00
commit f49554d063

View File

@ -77,6 +77,10 @@ class RemoteGraphicsView(QtGui.QWidget):
if sys.platform.startswith('win'):
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.
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:
self.shm = mmap.mmap(self.shmFile.fileno(), size, mmap.MAP_SHARED, mmap.PROT_READ)
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.
self.shmtag = "pyqtgraph_shmem_" + ''.join([chr((random.getrandbits(20)%25) + 97) for i in range(20)])
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:
self.shm.resize(size)