Remove useless (or undocumented) sleep() calls that were slowing down Python scipy build#599
Conversation
|
@gribozavr on a general note, the idea is to replace the run_cmd and run_cmd_qa with RunAsyncLoopLog.run (or subclass thereof for qa) from vsc-base. the slowness that you encounter is fixed in https://github.com/hpcugent/vsc-base/blob/master/lib/vsc/utils/run.py#L444. the qa code in vsc-base/run is not finished however. |
There was a problem hiding this comment.
this cannot be causing the issue (for very short commands, this is a speedup)
There was a problem hiding this comment.
Could you please explain why this is a speedup?
There was a problem hiding this comment.
well, not a speedup if you remove the inner sleep or make it conditional. (but the sleep will not cause real delay).
There was a problem hiding this comment.
OK, so it does not hurt, but it is not helping either. Thus it should be removed.
|
I discussed this a bit with Stijn, and it seems the sleeps are indeed a bit of overkill. However, running unit tests on this branch revelas an issue. A simple test like the ones below fails with the sleeps removed... (out, ec) = run_cmd_qa("echo question", {"question":"answer"})
self.assertEqual(out, "question\n")So, simply removing the sleeps seems to break |
|
can you run this with debug and check what goes wrong? and try with |
|
Rerunning the test with the initial sleep that was removed in diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py
index 910e10e..0663034 100644
--- a/easybuild/tools/filetools.py
+++ b/easybuild/tools/filetools.py
@@ -495,6 +495,7 @@ def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, re
except OSError, err:
_log.error("run_cmd_qa init cmd %s failed:%s" % (cmd, err))
+ time.sleep(0.1)
ec = p.poll()
stdoutErr = ''
oldLenOut = -1
@@ -561,7 +562,7 @@ def run_cmd_qa(cmd, qa, no_qa=None, log_ok=True, log_all=False, simple=False, re
))
# This sleep should not be needed.
- time.sleep(1)
+ #time.sleep(1)
ec = p.poll()
# Process stopped. Read all remaining data |
|
The (out, ec) = ft.run_cmd_qa("echo question; read x; echo $x", {"question": "answer"})
self.assertEqual(out, "question\nanswer\n")The patch mentioned above breaks this test, the sleep in the loop is quite critical to |
|
PR gribozavr#5 enhances the unit tests to make sure the proposed changes are OK. Whether they'll cause any issues should become clear when a full regtest is run. |
add/enhance unit tests, adjust comment
|
@boegel I think I now understand why that sleep was needed. |
|
OK, this seems ready to merge in. |
Remove useless (or undocumented) sleep() calls that were slowing down Python scipy build
This removes useless (or undocumented) sleep() calls. Calling read() on a pipe will block until data is available, so there is no reason to sleep().
There is one more sleep() that I marked with a comment in
run_cmd_qa. But because the function tries to emulate human input, the sleep() might be needed there if the program we interact with expects a delay (quite unlikely).