From b0b43c068e6e55ff6e987aed6a6a3736ded1a1ff 2014-01-23 21:42:54 From: Daniel Valdez Date: 2014-01-23 21:42:54 Subject: [PATCH] El envio de los archivos de imagen al servidor FTP se realiza mediante un thread. Por ahora esta funcion se ha aplicado a la clase SpectraPlot --- diff --git a/schainpy/model/graphics/figure.py b/schainpy/model/graphics/figure.py index 802d442..884a35d 100644 --- a/schainpy/model/graphics/figure.py +++ b/schainpy/model/graphics/figure.py @@ -4,9 +4,51 @@ import time, datetime import mpldriver from customftp import * +import Queue +import threading + +class FTP_Thread (threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self.exitFlag = 0 + self.queueLock = threading.Lock() + self.workQueue = Queue.Queue() + + def run(self): + self.send_data() + + def fin(self): + self.exitFlag = 1 + + def put_data(self, data): + # Fill the queue + self.queueLock.acquire() + self.workQueue.put(data) + self.queueLock.release() + + def send_data(self): + while not self.exitFlag: + if self.workQueue.qsize(): + + data = self.workQueue.get(True) + + try: + ftpObj = Ftp(host=data['server'], + username=data['username'], + passw=data['password'], + remotefolder=data['folder']) + + ftpObj.upload(data['figfilename']) + ftpObj.close() + except: + print ValueError, 'Error FTP' + print "don't worry still running the program" + + class Figure: __driver = mpldriver + __isConfigThread = False fig = None id = None @@ -177,6 +219,19 @@ class Figure: ftpObj.upload(figfilename) ftpObj.close() + def sendByFTP_Thread(self, figfilename, server, folder, username, password): + data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password} + + if not(self.__isConfigThread): + + self.thread = FTP_Thread() + self.thread.start() + self.__isConfigThread = True + + self.thread.put_data(data) + print 'thread.isAlive()', self.thread.isAlive() + + def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday diff --git a/schainpy/model/jroplot.py b/schainpy/model/jroplot.py index ed3e604..4c9c5f1 100644 --- a/schainpy/model/jroplot.py +++ b/schainpy/model/jroplot.py @@ -596,11 +596,9 @@ class SpectraPlot(Figure): ftp_file = os.path.join(path,'ftp','%s.png'%name) self.saveFigure(figpath, ftp_file) ftp_filename = os.path.join(figpath,ftp_file) - try: - self.sendByFTP(ftp_filename, server, folder, username, password) - except: - self.counter_imagwr = 0 - print ValueError, 'Error FTP' + self.sendByFTP_Thread(ftp_filename, server, folder, username, password) + self.counter_imagwr = 0 + self.counter_imagwr = 0