Commit a93eedcf authored by Remi Perenon's avatar Remi Perenon

Merge branch 'bugfix-interface_freezes_when_job_is_launched' into 'develop'

Bugfix interface freezes when job is launched

See merge request !47
parents 9b92672d e9e2bdba
Pipeline #4803 passed with stages
in 24 minutes and 37 seconds
......@@ -6,6 +6,7 @@
* FIXED issue #42 Plotter units could be inconsistent
* FIXED issue #41 Instrument resolution window froze GUI on macOS
* FIXED issue #40 MDANSE could not be used on Ubuntu Bionic systems (due to vtk dependency name)
* FIXED issue #38 Interface was frozen when jobs were launched. A delay of 2s is added at the end of jobs before suppressing the status file
version 1.2.1
--------------
......
......@@ -73,7 +73,17 @@ class Platform(object):
:rtype: str
'''
return os.path.join(self.package_directory(), 'Doc')
return os.path.join(self.package_directory(), 'Doc')
def jobs_launch_delay(self):
'''
Returns the delay (in seconds) for a job to launch.
This is used to determine the delay before updating the GUI and suppressing a job status file
:return: the delay (in seconds) for a job to launch
:rtype: float
'''
return 2.0
def api_path(self):
'''
......
......@@ -16,6 +16,8 @@ import collections
import cPickle
import datetime
import os
import threading
import time
from MDANSE import PLATFORM
from MDANSE.Framework.Status import Status
......@@ -47,8 +49,9 @@ class JobStatus(Status):
self.save_status()
def finish_status(self):
self.cleanup()
# Launch a thread that will wait before erasing the file
t= threading.Thread(target = self.cleanup)
t.start()
@property
def state(self):
......@@ -56,7 +59,8 @@ class JobStatus(Status):
return self._state
def cleanup(self):
# Wait before cleaning
time.sleep(PLATFORM.jobs_launch_delay())
try:
os.unlink(self._state['temporary_file'])
except:
......
......@@ -216,9 +216,12 @@ class JobControllerPanel(wx.ScrolledWindow):
event.Skip()
def msg_start_job(self,message):
self._jobsController.update()
t = threading.Thread(target=self.updateJobsController)
t.start()
def updateJobsController(self):
time.sleep(PLATFORM.jobs_launch_delay())
self._jobsController.update()
def on_display_info(self,event):
row = self._gbSizer.GetItemPosition(event.GetEventObject())[0]
......
......@@ -93,21 +93,33 @@ class JobPlugin(ComponentPlugin):
os.close(handle)
self._job.save(filename, parameters)
try:
from subprocess import DEVNULL
except ImportError:
DEVNULL = os.open(os.devnull, os.O_RDWR)
if PLATFORM.name == "windows":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
else:
startupinfo = None
#try:
# from subprocess import DEVNULL
#except ImportError:
# DEVNULL = os.open(os.devnull, os.O_RDWR)
try:
subprocess.check_output([sys.executable, filename], stdin=DEVNULL, stderr=DEVNULL)
subprocess.Popen([sys.executable, filename], startupinfo=startupinfo, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
message = e.output
else:
message = None
time.sleep(1)
PUBLISHER.sendMessage("msg_start_job",message=message)
PUBLISHER.sendMessage("msg_start_job",message=message)
if message is None:
d = wx.MessageDialog(None, 'Your analysis is performing. Do you want to close ?', 'Question', wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if d.ShowModal() == wx.ID_YES:
self.on_close(None)
def on_save(self, event=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment