44"""
55
66import os
7- import random
87import time
8+ from random import SystemRandom
99
1010import numpy
1111from ewokscore .task import Task
1212from silx .io import h5py_utils
1313
1414from ewoksppf import execute_graph
1515
16+ _random = SystemRandom ()
17+
1618
1719class GenerateData (
1820 Task ,
1921 input_names = ["nblocks" , "block_size" ],
2022 optional_input_names = ["block_index" ],
2123 output_names = ["image_stack" , "block_index" , "finished" ],
2224):
23-
2425 def run (self ):
2526 t0 = time .perf_counter ()
2627 block_index = self .get_input_value ("block_index" , 0 )
@@ -34,7 +35,7 @@ def run(self):
3435 self .outputs .block_index = block_index + 1
3536 self .outputs .finished = self .outputs .block_index >= self .inputs .nblocks
3637 t1 = time .perf_counter ()
37- print (f"{ block_size / (t1 - t0 )} images/sec" )
38+ print (f"{ block_size / (t1 - t0 )} images/sec" )
3839
3940
4041class IntegrateData (
@@ -43,25 +44,23 @@ class IntegrateData(
4344 optional_input_names = ["axis" , "delay" ],
4445 output_names = ["pattern_stack" , "block_index" ],
4546):
46-
4747 def run (self ):
4848 image_axis = self .get_input_value ("axis" , 0 )
4949 self .outputs .pattern_stack = self .inputs .image_stack .sum (axis = image_axis + 1 )
5050 self .outputs .block_index = self .inputs .block_index
5151
5252 delay = self .get_input_value ("delay" , 0 )
5353 if delay :
54- time .sleep (random .uniform (delay , delay * 1.5 ))
54+ time .sleep (_random .uniform (delay , delay * 1.5 ))
5555 else :
56- time .sleep (random .uniform (0 , 0.1 ))
56+ time .sleep (_random .uniform (0 , 0.1 ))
5757
5858
5959class SaveData (
6060 Task ,
6161 input_names = ["data_stack" , "block_index" , "filename" ],
6262 output_names = ["hdf5_url" ],
6363):
64-
6564 def run (self ):
6665 filename = os .path .abspath (self .inputs .filename )
6766 block_index = self .inputs .block_index
0 commit comments