Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

MPSharedMemory.py 683 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  1. import multiprocessing
  2. class MPSharedMemory:
  3. def __init__(self, size):
  4. self._size = size
  5. self._ar = multiprocessing.RawArray('B', self._size)
  6. self._mv = memoryview(self._ar).cast('B')
  7. def get_ar(self) -> multiprocessing.RawArray:
  8. """
  9. returns multiprocessing.RawArray
  10. """
  11. return self._ar
  12. def get_mv(self) -> memoryview:
  13. """
  14. returns byte-memoryview
  15. """
  16. return self._mv
  17. def __getstate__(self):
  18. d = self.__dict__.copy()
  19. d.pop('_mv')
  20. return d
  21. def __setstate__(self, d):
  22. self.__dict__.update(d)
  23. self._mv = memoryview(self._ar).cast('B')
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...