stats locking
This commit is contained in:
		
							parent
							
								
									e51a76116e
								
							
						
					
					
						commit
						21f62fd994
					
				
							
								
								
									
										20
									
								
								monitor.py
								
								
								
								
							
							
						
						
									
										20
									
								
								monitor.py
								
								
								
								
							|  | @ -20,6 +20,7 @@ | ||||||
| # along with System-Monitoring-Daemon.  If not, see <http://www.gnu.org/licenses/>. | # along with System-Monitoring-Daemon.  If not, see <http://www.gnu.org/licenses/>. | ||||||
| ## | ## | ||||||
| 
 | 
 | ||||||
|  | import threading | ||||||
| from socket import * | from socket import * | ||||||
| 
 | 
 | ||||||
| HOST = '' | HOST = '' | ||||||
|  | @ -31,8 +32,27 @@ MAX_QUEUE = 5 | ||||||
| 
 | 
 | ||||||
| class Stats: | class Stats: | ||||||
| 	def __init__(self): | 	def __init__(self): | ||||||
|  | 		self.read_lock = threading.Lock() | ||||||
|  | 		self.write_lock = threading.Lock() | ||||||
|  | 
 | ||||||
| 		self.cpu_load = 50 | 		self.cpu_load = 50 | ||||||
| 
 | 
 | ||||||
|  | 	def acquire_read(self): | ||||||
|  | 		self.read_lock.acquire() | ||||||
|  | 		self.write_lock.acquire() | ||||||
|  | 
 | ||||||
|  | 	def release_read(self): | ||||||
|  | 		self.write_lock.release() | ||||||
|  | 		self.read_lock.release() | ||||||
|  | 
 | ||||||
|  | 	def acquire_write(self): | ||||||
|  | 		self.write_lock.acquire() | ||||||
|  | 
 | ||||||
|  | 	def release_write(self): | ||||||
|  | 		self.write_lock.release() | ||||||
|  | 		 | ||||||
|  | 	 | ||||||
|  | 
 | ||||||
| class ClientHandler: | class ClientHandler: | ||||||
| 	def __init__(self, stats): | 	def __init__(self, stats): | ||||||
| 		self.stats = stats | 		self.stats = stats | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue