diff --git a/Changelog.md b/Changelog.md index 7789eb6..f1c7d5f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +# 2.2.6 + +## Common + +- Restored functionality of `sequential` runtime option + # 2.2.5 ## CLI diff --git a/cace/__version__.py b/cace/__version__.py index 0260f56..6582762 100644 --- a/cace/__version__.py +++ b/cace/__version__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '2.2.5' +__version__ = '2.2.6' if __name__ == '__main__': print(__version__, end='') diff --git a/cace/common/electrical_parameter.py b/cace/common/electrical_parameter.py index 4d5b39e..f369edf 100755 --- a/cace/common/electrical_parameter.py +++ b/cace/common/electrical_parameter.py @@ -90,34 +90,55 @@ def run(self): self.cancel_point() - with ThreadPool(processes=max(cpu_count() - 1, 1)) as mypool: + # Run simulation jobs sequentially + if self.runtime_options['sequential']: - # Start the jobs - jobs = [] for sim in self.queued_jobs: print(f'{self.param["name"]}: Starting task') - jobs.append(mypool.apply_async(sim.run, callback=self.cb_sims)) - # Wait for completion - while 1: + # Start simulation job as single thread + sim.start() + presult = sim.join() + self.cancel_point() - # Check if all tasks have completed - if all([job.ready() for job in jobs]): - print(f'{self.param["name"]}: All tasks done') - break + self.new_testbenches[presult['sequence']] = presult + + if self.cb_sims: + self.cb_sims() + + # Run simulation jobs in parallel + else: + with ThreadPool(processes=max(cpu_count() - 1, 1)) as mypool: + + # Start the jobs + jobs = [] + for sim in self.queued_jobs: + print(f'{self.param["name"]}: Starting task') + jobs.append( + mypool.apply_async(sim.run, callback=self.cb_sims) + ) + + # Wait for completion + while 1: + self.cancel_point() + + # Check if all tasks have completed + if all([job.ready() for job in jobs]): + print(f'{self.param["name"]}: All tasks done') + break - time.sleep(0.1) + time.sleep(0.1) - # Get the restuls - for job in jobs: - presult = job.get() + # Get the restuls + for job in jobs: + presult = job.get() - if presult: - # TODO make testbench name the key for easier access - self.new_testbenches[presult['sequence']] = presult + if presult: + # TODO make testbench name the key for easier access + self.new_testbenches[presult['sequence']] = presult - jobs = [] + jobs = [] self.cancel_point() diff --git a/cace/common/simulation_job.py b/cace/common/simulation_job.py index 45bca30..230abd3 100755 --- a/cace/common/simulation_job.py +++ b/cace/common/simulation_job.py @@ -39,6 +39,7 @@ def __init__( self.spiceproc = None super().__init__(*args, **kwargs) + self._return = None def cancel(self, cancel_cb): # print(f'{self.param["name"]}: Cancel simulation: {self.testbenchlist}') @@ -112,7 +113,13 @@ def run(self): if os.path.isfile(outfilename): os.remove(outfilename) - return tbzero if simulations > 0 else None + # For when the join function is called + self._return = tbzero if simulations > 0 else None + return self._return + + def join(self, *args): + threading.Thread.join(self, *args) + return self._return def collate_after_simulation(self, param, collnames, testbenchlist, debug): # Sanity check: If there is only one testbench, then there is diff --git a/cace/gui/consoletext.py b/cace/gui/consoletext.py index 4aa54df..a43c69a 100755 --- a/cace/gui/consoletext.py +++ b/cace/gui/consoletext.py @@ -40,6 +40,9 @@ class StderrRedirector(IORedirector): def write(self, str): self.text_area.write(str, True) + def flush(self): + pass + def __init__(self, master=None, cnf={}, **kw): """See the __init__ for Tkinter.Text."""