1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing the class for threaded and non-threaded analysis execution."""
25
26
27 import sys
28 from threading import Thread
29 from traceback import print_exc
30
31
32 from relax_errors import RelaxImplementError
33 from status import Status; status = Status()
34
35
37 """The analysis execution object."""
38
39 - def __init__(self, gui, data, data_index, thread=True):
40 """Set up the analysis execution object.
41
42 @param gui: The GUI object.
43 @type gui: wx object
44 @param data: The data container with all data for the analysis.
45 @type data: class instance
46 @param data_index: The index of the analysis in the relax data store.
47 @type data_index: int
48 @keyword thread: The flag for turning threading on and off.
49 @type thread: bool
50 """
51
52
53 self.gui = gui
54 self.data = data
55 self.data_index = data_index
56
57
58 if thread:
59
60 Thread.__init__(self)
61
62
63 self.daemon = True
64
65
66 else:
67
68 self.join = self._join
69 self.start = self._start
70
71
73 """Dummy join() method for non-threaded execution."""
74
75
77 """Replacement start() method for when execution is not threaded."""
78
79
80 self.run()
81
82
84 """Execute the thread (or pseudo-thread)."""
85
86
87 try:
88 self.run_analysis()
89
90
91 except:
92
93 status.exception_queue.put([self.data_index, sys.exc_info()])
94
95
96 sys.stderr.write("Exception raised in thread.\n\n")
97 print_exc()
98 sys.stderr.write("\n\n\n")
99
100
101 if status.exec_lock.locked():
102 status.exec_lock.release()
103
104
106 """Execute the analysis
107
108 This method must be overridden.
109 """
110
111 raise RelaxImplementError
112