Beispiel #1
0
 def start(self):  
     """
     Start threads and directory observer.
     """
     #start threads
     
     for threadid in range(1,self.options.threads):
         print "start proc [",threadid,"]"
        
         worker=Process(target=funcworker, args=(self,threadid))
         worker.daemon=True
         self.pool.append(worker)
         worker.start() 
         #self.processimage(picture,options)
     self.starttime=time.time() 
     if self.options.watch:
         eventhandler=addtoqueue(self.picturequeue)
         self.observer = Observer()
         self.observer.schedule(eventhandler, self.args[0], recursive=True)
         self.observer.start()
     #We let the master process do some work because its useful for matplotlib.
     if not self.options.nowalk:
         self.fillqueuewithexistingfiles()
     if self.options.servermode:
          
          context = zmq.Context()
          socket = context.socket(zmq.REQ)
          tokenlist=  self.conf['Server'].split(":")
          
          server=":".join([tokenlist[0],tokenlist[1],self.options.serverport])
          print server
          socket.connect (server)
          from Leash import addauthentication
     try:
         while ( self.options.servermode or 
                 (not self.picturequeue.empty()) 
                 or (self.dirwalker and self.dirwalker.is_alive() )
                 or self.options.watch): 
                 try:
                     picture = self.picturequeue.get(timeout=1)
                 except Empty:
                     continue
                 lastfile, data =self.procimage(picture,0)
                 
                 if self.options.servermode:
                     request={"command":"putplotdata","argument":{"data":{
                             "result":"plot","data":{"filename":lastfile,"graphs":data,
                                                     "stat":{}}
                               }}}
                     socket.send_multipart([json.dumps(addauthentication( request,self.conf))])
                     socket.recv()
                 if np.mod(self.allp.value,500)==0:
                     self.timreport()
     except KeyboardInterrupt:
         pass
     if self.options.servermode:
         context.destroy()
     self.stop()
     self.timreport()
     return self.allp.value, time.time()-self.starttime
Beispiel #2
0
    def start(self):
        """
        Start threads and directory observer.
        """
        #start threads

        for threadid in range(1, self.options.threads):
            print "start proc [", threadid, "]"

            worker = Process(target=funcworker, args=(self, threadid))
            worker.daemon = True
            self.pool.append(worker)
            worker.start()
            #self.processimage(picture,options)
        self.starttime = time.time()
        if self.options.watch:
            eventhandler = addtoqueue(self.picturequeue)
            self.observer = Observer()
            self.observer.schedule(eventhandler, self.args[0], recursive=True)
            self.observer.start()
        #We let the master process do some work because its useful for matplotlib.
        if not self.options.nowalk:
            self.fillqueuewithexistingfiles()
        if self.options.servermode:

            context = zmq.Context()
            socket = context.socket(zmq.REQ)
            tokenlist = self.conf['Server'].split(":")

            server = ":".join(
                [tokenlist[0], tokenlist[1], self.options.serverport])
            print server
            socket.connect(server)
            from Leash import addauthentication
        try:
            while (self.options.servermode or (not self.picturequeue.empty())
                   or (self.dirwalker and self.dirwalker.is_alive())
                   or self.options.watch):
                try:
                    picture = self.picturequeue.get(timeout=1)
                except Empty:
                    continue
                lastfile, data = self.procimage(picture, 0)

                if self.options.servermode:
                    request = {
                        "command": "putplotdata",
                        "argument": {
                            "data": {
                                "result": "plot",
                                "data": {
                                    "filename": lastfile,
                                    "graphs": data,
                                    "stat": {}
                                }
                            }
                        }
                    }
                    socket.send_multipart(
                        [json.dumps(addauthentication(request, self.conf))])
                    socket.recv()
                if np.mod(self.allp.value, 500) == 0:
                    self.timreport()
        except KeyboardInterrupt:
            pass
        if self.options.servermode:
            context.destroy()
        self.stop()
        self.timreport()
        return self.allp.value, time.time() - self.starttime
Beispiel #3
0
    def start(self):
        """
        Start threads and directory observer.
        """
        #start threads

        for threadid in range(1, self.options.threads):
            print "start proc [", threadid, "]"

            worker = Process(target=funcworker, args=(self, threadid))
            worker.daemon = True
            self.pool.append(worker)
            worker.start()
            #self.processimage(picture,options)
        self.starttime = time.time()
        if self.options.watch:
            eventhandler = addtoqueue(self.picturequeue)
            self.observer = Observer()
            self.observer.schedule(eventhandler, self.args[0], recursive=True)
            self.observer.start()
        #We let the master process do some work because its useful for matplotlib.
        if not self.options.nowalk:
            self.fillqueuewithexistingfiles()
        if self.options.servermode:

            from Leash import addauthentication
        try:
            while (self.options.servermode or (not self.picturequeue.empty())
                   or (self.dirwalker and self.dirwalker.is_alive())
                   or self.options.watch):
                try:
                    picture = self.picturequeue.get(timeout=1)
                except Empty:
                    continue

#in Case something goes wrong
                try:
                    lastfile, data = self.procimage(picture, 0)
                except:
                    continue

                if self.options.servermode:
                    request = {
                        "command": "putplotdata",
                        "argument": {
                            "data": {
                                "result": "plot",
                                "data": {
                                    "filename": lastfile,
                                    "graphs": data,
                                    "stat": {}
                                }
                            }
                        }
                    }

                    self.plotdataqueue.put(request)
                if np.mod(self.allp.value, 500) == 0:
                    self.timreport()
        except KeyboardInterrupt:
            pass

        self.stop()
        self.timreport()
        return self.allp.value, time.time() - self.starttime