ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 377ca62f was
d85c194,
checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago
|
Remaining modules refactored
|
-
Property mode set to
100644
|
File size:
2.4 KB
|
Line | |
---|
1 | """ |
---|
2 | Thread handler used to load data |
---|
3 | """ |
---|
4 | import time |
---|
5 | from sas.sascalc.data_util.calcthread import CalcThread |
---|
6 | from sas.sascalc.dataloader.loader import Loader |
---|
7 | |
---|
8 | class DataReader(CalcThread): |
---|
9 | """ |
---|
10 | Load a data given a filename |
---|
11 | """ |
---|
12 | def __init__(self, path, completefn=None, |
---|
13 | updatefn=None, |
---|
14 | yieldtime=0.01, |
---|
15 | worktime=0.01 |
---|
16 | ): |
---|
17 | CalcThread.__init__(self, completefn, |
---|
18 | updatefn, |
---|
19 | yieldtime, |
---|
20 | worktime) |
---|
21 | self.path = path |
---|
22 | #Instantiate a loader |
---|
23 | self.loader = Loader() |
---|
24 | self.starttime = 0 |
---|
25 | |
---|
26 | def isquit(self): |
---|
27 | """ |
---|
28 | @raise KeyboardInterrupt: when the thread is interrupted |
---|
29 | """ |
---|
30 | try: |
---|
31 | CalcThread.isquit(self) |
---|
32 | except KeyboardInterrupt: |
---|
33 | raise KeyboardInterrupt |
---|
34 | |
---|
35 | |
---|
36 | def compute(self): |
---|
37 | """ |
---|
38 | read some data |
---|
39 | """ |
---|
40 | self.starttime = time.time() |
---|
41 | try: |
---|
42 | data = self.loader.load(self.path) |
---|
43 | self.complete(data=data) |
---|
44 | except KeyboardInterrupt: |
---|
45 | # Thread was interrupted, just proceed and re-raise. |
---|
46 | # Real code should not print, but this is an example... |
---|
47 | raise |
---|
48 | |
---|
49 | class GenReader(CalcThread): |
---|
50 | """ |
---|
51 | Load a sld data given a filename |
---|
52 | """ |
---|
53 | def __init__(self, path, loader, |
---|
54 | completefn=None, |
---|
55 | updatefn=None, |
---|
56 | yieldtime=0.01, |
---|
57 | worktime=0.01 |
---|
58 | ): |
---|
59 | CalcThread.__init__(self, completefn, |
---|
60 | updatefn, |
---|
61 | yieldtime, |
---|
62 | worktime) |
---|
63 | self.path = path |
---|
64 | #Instantiate a loader |
---|
65 | self.loader = loader |
---|
66 | self.starttime = 0 |
---|
67 | |
---|
68 | def isquit(self): |
---|
69 | """ |
---|
70 | @raise KeyboardInterrupt: when the thread is interrupted |
---|
71 | """ |
---|
72 | try: |
---|
73 | CalcThread.isquit(self) |
---|
74 | except KeyboardInterrupt: |
---|
75 | raise KeyboardInterrupt |
---|
76 | |
---|
77 | |
---|
78 | def compute(self): |
---|
79 | """ |
---|
80 | read some data |
---|
81 | """ |
---|
82 | self.starttime = time.time() |
---|
83 | try: |
---|
84 | data = self.loader.read(self.path) |
---|
85 | self.complete(data=data) |
---|
86 | except: |
---|
87 | # Thread was interrupted, just proceed and re-raise. |
---|
88 | # Real code should not print, but this is an example... |
---|
89 | raise |
---|
Note: See
TracBrowser
for help on using the repository browser.