scans: parallel execution does not publish expected number of points
When testing the writer, I noticed that when running scans in parallel, I did not always get the expected number of points. I sometimes get more points than expected. I have the impression that this is a bug that was introduced recently (I'm working on the current master). Run the code below in any bliss session and wait for it to explode (runs fine with parallel=False
but not when parallel=True
):
import gevent
import numpy
from bliss.common.session import get_current
from bliss.data.node import get_node
def runtest(*detectors, parallel=True):
# Count point progress in published channels
npoints = {}
session_node = get_node(get_current().name)
def listen(filter='channel'):
for event_type, node in session_node.iterator.walk_events(filter=filter):
scan_node = node
while scan_node.type != "scan":
scan_node = scan_node.parent
npoints[scan_node.info['scan_nb']] = len(node.get(0, -1))
listener = gevent.spawn(listen)
gevent.sleep(5)
# Run scans parallel or in series
scans = [loopscan(int(n), 0.1, *detectors, run=False, save=False)
for n in numpy.random.randint(10, 20 , 5)]
if parallel:
greenlets = [gevent.spawn(s.run) for s in scans]
gevent.joinall(greenlets)
else:
for s in scans:
s.run()
listener.kill()
listener.join()
# Measured points equal to requested points?
ok = True
for s in scans:
scan_nb = s.scan_info['scan_nb']
requested = s.scan_info['npoints']
measured = npoints.get(scan_nb, 0)
ok &= measured == requested
print('{}. {}: collected points = {}'
.format(scan_nb, s.scan_info['title'], measured))
return ok
while runtest(parallel=True):
pass