added onionrthreads to replace communicator timers
This commit is contained in:
		
							parent
							
								
									6f1daf50d3
								
							
						
					
					
						commit
						0b34aa7385
					
				
					 1 changed files with 25 additions and 0 deletions
				
			
		
							
								
								
									
										25
									
								
								src/onionrthreads/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/onionrthreads/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| from typing import Callable | ||||
| from typing import Iterable | ||||
| 
 | ||||
| from threading import Thread | ||||
| 
 | ||||
| from utils.bettersleep import better_sleep | ||||
| 
 | ||||
| 
 | ||||
| def _onionr_thread(func: Callable, args: Iterable, | ||||
|                    sleep: int, initial_sleep): | ||||
|     better_sleep(initial_sleep) | ||||
|     while True: | ||||
|         func(*args) | ||||
|         better_sleep(sleep) | ||||
| 
 | ||||
| 
 | ||||
| def add_onionr_thread( | ||||
|         func: Callable, args: Iterable, | ||||
|         sleep: int, initial_sleep: int = 5): | ||||
|     """Spawn a new onionr thread that exits when the main thread does. | ||||
| 
 | ||||
|     Runs in an infinite loop with sleep between calls | ||||
|     Passes in an interable args and sleep variables""" | ||||
|     Thread(target=_onionr_thread, | ||||
|            args=(func, args, sleep, initial_sleep), daemon=True).start() | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue