Created
July 28, 2016 11:14
-
-
Save gengen1988/b479e9e06a205a18228cca345a8b3760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import threading | |
import time | |
def call_async(on_exit, *popen_args, **popen_kw_args): | |
def run_in_thread(on_exit): | |
result_code = proc.wait() | |
if result_code == 0: | |
return on_exit(None, proc) | |
else: | |
return on_exit(result_code, proc) | |
proc = subprocess.Popen(*popen_args, **popen_kw_args) | |
thread = threading.Thread(target=run_in_thread, args=[on_exit]) | |
thread.start() | |
return proc | |
def on_complete(rc): | |
print "complete: " + str(rc) | |
print "--- %s seconds ---" % (time.time() - start_time) | |
start_time = time.time() | |
proc = call_async(on_complete, [ | |
"rec", "aaaa.wav" | |
], cwd="tests") | |
print "delay" | |
time.sleep(3) | |
print "ending" | |
proc.kill() | |
print "stopped" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment