Skip to content

Commit

Permalink
test code for using daemon threads in drmaa_wrapper::run_job_locally(…
Browse files Browse the repository at this point in the history
…). Without daemon threads, the subprocesses cannot be interrupted by Ctrl-C
  • Loading branch information
bunbun committed Apr 21, 2015
1 parent 1176353 commit 4c99630
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ruffus/drmaa_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,14 @@ def run_job_locally (cmd_str, logger = None, job_environment = None, working_dir
stdoutQ = Queue()
stdout_t = threading.Thread(target=enqueue_output, args=(process.stdout, stdoutQ, sys.stdout if local_echo else None))
stderr_t = threading.Thread(target=enqueue_output, args=(process.stderr, stderrQ, sys.stderr if local_echo else None))
# if daemon = False, sub process cannot be interrupted by Ctrl-C
stdout_t.daemon = True
stderr_t.daemon = True
stderr_t.start()
stdout_t.start()
process.wait()
stdout_t.join()
stderr_t.join()

stdout, stderr = [], []
try:
Expand Down
22 changes: 16 additions & 6 deletions ruffus/test/slow_process_for_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
import sys, os, time
print (" ", os.getcwd(), file = sys.stderr)
print (" ", os.environ, file = sys.stderr)
for ii in range(4):
sys.stderr.write(" Stderr %d\n" % ii)
sys.stderr.flush()
sys.stdout.write(" Stdout %d\n" % ii)
sys.stdout.flush()
time.sleep(0.5)
loop_variable = 0
loop_limit = 4
while True:
if loop_variable >= loop_limit:
break
try:
sys.stderr.write(" Stderr %d\n" % loop_variable)
sys.stderr.flush()
sys.stdout.write(" Stdout %d\n" % loop_variable)
sys.stdout.flush()
loop_variable += 1
time.sleep(0.5)
except:
sys.stderr.write(" Ignore Exception. Now you have made me angry: I won't stop till 100\n")
loop_limit = 100
pass

0 comments on commit 4c99630

Please sign in to comment.