Skip to content

Commit ffe4e85

Browse files
committed
Pure python Modify for PR643
Signed-off-by: Miao, Hongda <[email protected]>
1 parent 7d7355b commit ffe4e85

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/lava/magma/runtime/message_infrastructure/py_multiprocessing.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
import multiprocessing as mp
1212
import os
13-
from multiprocessing.managers import SharedMemoryManager
1413
import traceback
1514

1615
from lava.magma.runtime.message_infrastructure.interfaces import ChannelType
1716
from lava.magma.runtime.message_infrastructure import Channel
1817
from lava.magma.runtime.message_infrastructure.pypychannel import PyPyChannel
18+
from lava.magma.runtime.message_infrastructure.shared_memory_manager import (
19+
SharedMemoryManager,
20+
)
21+
1922
try:
2023
from lava.magma.compiler.channels.cpychannel import \
2124
CPyChannel, PyCChannel
@@ -45,6 +48,7 @@ def __init__(self, *args, **kwargs):
4548
mp.Process.__init__(self, *args, **kwargs)
4649
self._pconn, self._cconn = mp.Pipe()
4750
self._exception = None
51+
self._is_done = False
4852

4953
def run(self):
5054
try:
@@ -54,10 +58,20 @@ def run(self):
5458
tb = traceback.format_exc()
5559
self._cconn.send((e, tb))
5660

61+
def join(self):
62+
if not self._is_done:
63+
super().join()
64+
super().close()
65+
if self._pconn.poll():
66+
self._exception = self._pconn.recv()
67+
self._cconn.close()
68+
self._pconn.close()
69+
self._is_done = True
70+
5771
@property
5872
def exception(self):
5973
"""Exception property."""
60-
if self._pconn.poll():
74+
if not self._is_done and self._pconn.poll():
6175
self._exception = self._pconn.recv()
6276
return self._exception
6377

tests/lava/magma/compiler/channels/test_channel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import unittest
77
import time
88
from multiprocessing import Process
9-
from multiprocessing.managers import SharedMemoryManager
109
from lava.magma.runtime.message_infrastructure import (
1110
create_channel,
1211
Channel,
1312
)
13+
from lava.magma.runtime.message_infrastructure.shared_memory_manager import (
14+
SharedMemoryManager
15+
)
1416

1517

1618
class MockInterface:

0 commit comments

Comments
 (0)