def cleanup(self): """ Close pipes, remove files and temp dir and kills the transcoding process. """ if self.__cleanup_executed: return s = Suppress(Exception) # Stop timer if any if self.timer is not None: self.timer.cancel() # Stop all threads with s: self.audio.stop() with s: self.video.stop() with s: self.data_processing.stop() # Remove entry from database if self._id: db.mobile.update({'_id': self._id}, {'$set': {'active': False}}) # Remove temp directory and thumbnail with s: shutil.rmtree(self.tmpdir) with s: os.remove(self.thumbnail_path) WebsocketBroadcast.select('mobile_location').cls.broadcast_message({ 'name': self.get_stream_name(), 'info': 'finished' }) self.__cleanup_executed = True if s.errors: show.warn('Errors during cleanup:', *s.errors, sep='\n', end='\n\n') show('Mobile stream "{0}" has ended'.format(self._id))
def _handle_coord(self, data): obj = {'time': datetime.datetime.utcnow(), 'coord': [data['latitude'], data['longitude']]} self.latest_position = obj db.mobile.update({'_id': self.parent._id}, {'$push': {'position': obj}}) WebsocketBroadcast.select('mobile_location').cls.broadcast_message({ 'name': self.parent.get_stream_name(), 'info': obj }) show('Stream: {0} | {1} | {2}'.format( self.parent._id, obj['time'], obj['coord']) )