Created
November 16, 2012 21:28
-
-
Save dongliu/4091076 to your computer and use it in GitHub Desktop.
snapshot pv multi-threading
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
# ... | |
from multiprocessing import Process, Manager | |
def get(d, pv_name, size, start, pid): | |
pv = PV(pv_name) | |
if pv.wait_for_connection(timeout=1.0): | |
d[pv_name] = pv.get(use_monitor=False) | |
else: | |
d[pv_name] = 'not connected' | |
if len(d) == size: | |
print int(round((time.time() - start) * 1000)) | |
os.kill(pid, signal.SIGTERM) | |
# ... | |
size = len(pv_list) | |
manager = Manager() | |
d = manager.dict() | |
start = time.time() | |
pid = os.getpid() | |
for pv_name in pv_list: | |
p = Process(target=get, args=(d, pv_name, size, start, pid)) | |
p.start() | |
time.sleep(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment