def init_updates(): global save_interval, idle_interval, last_save_time, last_idle_time from sagenb.misc.misc import walltime save_interval = notebook.conf()['save_interval'] idle_interval = notebook.conf()['idle_check_interval'] last_save_time = walltime() last_idle_time = walltime()
def notebook_idle_check(self): t = walltime() if t > self.last_idle_time + self.idle_interval: if t > self.last_idle_time + self.idle_interval: self.notebook.update_worksheet_processes() self.notebook.quit_idle_worksheet_processes() self.last_idle_time = t
def notebook_save_check(): global last_save_time from sagenb.misc.misc import walltime t = walltime() if t > last_save_time + save_interval: notebook.save() last_save_time = t
def _check_for_walltimeout(self): """ Check if the walltimeout has been reached, and if so, kill this worksheet process. """ if (self._is_started and \ self._max_walltime and self._start_walltime and \ walltime() - self._start_walltime > self._max_walltime): self.quit()
def notebook_idle_check(): global last_idle_time from sagenb.misc.misc import walltime t = walltime() if t > last_idle_time + idle_interval: notebook.update_worksheet_processes() notebook.quit_idle_worksheet_processes() last_idle_time = t
def start(self): """ Start this worksheet process running. """ self._expect = pexpect.spawn(self.command()) self._is_started = True self._is_computing = False self._number = 0 self._read() self._start_walltime = walltime()
def test_allpub(self): """ View every single one of the published worksheets on the Sage notebook server. """ if self._verbose: print "testing download of all published worksheets..." tm = walltime() pub = self.get_urls_of_published_worksheets() try: alarm(self._url_timeout) for i, X in enumerate(pub): t0 = walltime() self._geturl(X, use_alarm=False) if self._verbose: print "Got %s [%s/%s] %.2f seconds"%(X,i+1,len(pub), walltime(t0)) return walltime(tm) except KeyboardInterrupt: return TIMEOUT finally: cancel_alarm()
def test_allpub(self): """ View every single one of the published worksheets on the FEMhub online lab server. """ if self._verbose: print "testing download of all published worksheets..." tm = walltime() pub = self.get_urls_of_published_worksheets() try: alarm(self._url_timeout) for i, X in enumerate(pub): t0 = walltime() self._geturl(X, use_alarm=False) if self._verbose: print "Got %s [%s/%s] %.2f seconds"%(X,i+1,len(pub), walltime(t0)) return walltime(tm) except KeyboardInterrupt: return TIMEOUT finally: cancel_alarm()
def notebook_save_check(self): t = walltime() if t > self.last_save_time + self.save_interval: with global_lock: # if someone got the lock before we did, they might have saved, # so we check against the last_save_time again # we don't put the global_lock around the outer loop since we don't need # it unless we are actually thinking about saving. if t > self.last_save_time + self.save_interval: self.notebook.save() self.last_save_time = t
def download_worksheets(): from sagenb.misc.misc import walltime, tmp_filename t = walltime() print "Starting zipping a group of worksheets in a separate thread..." zip_filename = tmp_filename() + ".zip" # child worksheet_names = set() if 'filenames' in request.values: import json filenames = json.loads(request.values['filenames']) worksheets = [ g.notebook.get_worksheet_with_filename(x.strip()) for x in filenames if len(x.strip()) > 0 ] else: worksheets = g.notebook.worksheet_list_for_user(g.username) import zipfile zip = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_STORED) for worksheet in worksheets: sws_filename = tmp_filename() + '.sws' g.notebook.export_worksheet(worksheet.filename(), sws_filename) entry_name = worksheet.name() if entry_name in worksheet_names: i = 2 while ("%s_%s" % (entry_name, i)) in worksheet_names: i += 1 entry_name = "%s_%s" % (entry_name, i) zip.write(sws_filename, entry_name + ".sws") os.unlink(sws_filename) zip.close() r = open(zip_filename, 'rb').read() os.unlink(zip_filename) print "Finished zipping %s worksheets (%s seconds)" % (len(worksheets), walltime(t)) response = current_app.make_response(r) response.headers['Content-Type'] = 'application/zip' return response
def download_worksheets(): from sagenb.misc.misc import walltime, tmp_filename t = walltime() print "Starting zipping a group of worksheets in a separate thread..." zip_filename = tmp_filename() + ".zip" # child worksheet_names = set() if 'filenames' in request.values: import json filenames = json.loads(request.values['filenames']) worksheets = [g.notebook.get_worksheet_with_filename(x.strip()) for x in filenames if len(x.strip()) > 0] else: worksheets = g.notebook.worksheet_list_for_user(g.username) import zipfile zip = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_STORED) for worksheet in worksheets: sws_filename = tmp_filename() + '.sws' g.notebook.export_worksheet(worksheet.filename(), sws_filename) entry_name = worksheet.name() if entry_name in worksheet_names: i = 2 while ("%s_%s" % (entry_name, i)) in worksheet_names: i += 1 entry_name = "%s_%s" % (entry_name, i) zip.write(sws_filename, entry_name + ".sws") os.unlink(sws_filename) zip.close() r = open(zip_filename, 'rb').read() os.unlink(zip_filename) print "Finished zipping %s worksheets (%s seconds)"%(len(worksheets), walltime(t)) response = current_app.make_response(r) response.headers['Content-Type'] = 'application/zip' return response
def notebook_save_check(): global last_save_time from sagenb.misc.misc import walltime t = walltime() if t > last_save_time + save_interval: with global_lock: # if someone got the lock before we did, they might have saved, # so we check against the last_save_time again # we don't put the global_lock around the outer loop since we don't need # it unless we are actually thinking about saving. if t > last_save_time + save_interval: notebook.save() last_save_time = t
def notebook_idle_check(): global last_idle_time from sagenb.misc.misc import walltime t = walltime() if t > last_idle_time + idle_interval: with global_lock: # if someone got the lock before we did, they might have already idled, # so we check against the last_idle_time again # we don't put the global_lock around the outer loop since we don't need # it unless we are actually thinking about quitting worksheets if t > last_idle_time + idle_interval: notebook.update_worksheet_processes() notebook.quit_idle_worksheet_processes() last_idle_time = t
def init_updates(self): self.save_interval = self.notebook.conf()['save_interval'] self.idle_interval = self.notebook.conf()['idle_check_interval'] self.last_save_time = walltime() self.last_idle_time = walltime()