Skip to content

Commit 5c4979a

Browse files
committed
Fix issue of pipe closing prematurely (after 10 seconds).
Now wait for pipe to be ready to be read indefinitely
1 parent 5625eff commit 5c4979a

File tree

4 files changed

+4
-23
lines changed

4 files changed

+4
-23
lines changed

src/pymadng/madp_object.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,6 @@ def __enter__(self):
467467
return self
468468

469469
def __exit__(self, exc_type, exc_value, tb):
470-
# Close the process, as the with statement is finished
471-
# assert self.__process.send("py:send('closing')").recv("close") == "closing", (
472-
# "Error in waiting for the process to close"
473-
# ) # If you can test this does anything, please implement it. I have a feeling it does (jgray 2025)
474470
self.__process.close()
475471

476472
# ---------------------------------------------------------------------------------------------------#

src/pymadng/madp_pymad.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def close(self) -> None:
237237
"""Close the pipes and wait for the process to finish"""
238238
if self.process.poll() is None: # If process is still running
239239
self.send(f"{self.py_name}:__fin()") # Tell the mad side to finish
240-
open_pipe = select.select([self.mad_read_stream], [], [], 10)
240+
open_pipe = select.select([self.mad_read_stream], [], [])
241241
if open_pipe[0]:
242242
# Wait for the mad side to finish (variable name in case of errors that need to be caught elsewhere)
243243
close_msg = self.recv("closing")

tests/comm_test.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,6 @@ def test_print(self):
390390
mad.send("py:send('hello world')")
391391
self.assertEqual(mad.recv(), "hello world") # Check printing does not affect pipe
392392

393-
# def test_closing(self):
394-
# This test doesn't work. I find every now and then my mad process is closed before
395-
# MAD-NG has finished executing. I don't know why this happens, and this test does
396-
# not reproduce the error. (jgray 2025)
397-
# with MAD() as mad:
398-
# mad.send('for i = 1, 1e10 do a = 1 + 4 end') # This will catch times when the mad process is closed early
399-
# mad.send('io.open("test.txt", "w"):close()')
400-
# created_file = Path("test.txt")
401-
# self.assertTrue(created_file.exists())
402-
# created_file.unlink()
403-
404393
class TestDebug(unittest.TestCase):
405394
test_log1 = inputs_folder/"test.log"
406395
def test_logfile(self):

tests/inputs/example.log

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
***pymad.recv: binary data 4 bytes
22
***pymad.recv: [io.stdout:setvbuf('line')] 25 bytes
33
***pymad.recv: binary data 4 bytes
4-
***pymad.recv: [py:send(1)] 10 bytes
5-
***pymad.send: [int_] 4 bytes
4+
***pymad.recv: [py:send('started')] 18 bytes
5+
***pymad.send: [str_] 4 bytes
66
***pymad.send: binary data 4 bytes
7+
***pymad.send: [started] 7 bytes
78
***pymad.recv: binary data 4 bytes
89
***pymad.recv: [element = MAD.element
910
sequence = MAD.sequence
@@ -37,11 +38,6 @@ end
3738
_last = {}
3839
] 138 bytes
3940
***pymad.recv: binary data 4 bytes
40-
***pymad.recv: [py:send('closing')] 18 bytes
41-
***pymad.send: [str_] 4 bytes
42-
***pymad.send: binary data 4 bytes
43-
***pymad.send: [closing] 7 bytes
44-
***pymad.recv: binary data 4 bytes
4541
***pymad.recv: [py:__fin()] 10 bytes
4642
***pymad.send: [str_] 4 bytes
4743
***pymad.send: binary data 4 bytes

0 commit comments

Comments
 (0)