def exec(_sch_h , _sch_m , _sch_s): now_ = (datetime.datetime.now()) y = int(str(now_)[0:4]) m = int(str(now_)[5:7]) d = int(str(now_)[8:10]) exec_time = datetime.datetime(y, m, d, _sch_h, _sch_m, _sch_s, 0) print("Sch Execution Time = " , exec_time) print("Current Time = " , now_ , end="\r") while True: now_ = (datetime.datetime.now()) #print("Current Time = " , now_ , end="\r") if(math.isclose((now_.timestamp()) ,(exec_time.timestamp()) , rel_tol=1e-14 , abs_tol=0)): #__main__.t1 = time.perf_counter() break print("\n\nVoila") __main__.log("Scheduled Execution Time = " , exec_time.timestamp()) __main__.log("Real Execution Time = " , now_.timestamp())
def _put_queue_value(self, message): def message_is_redundant(): return self.last_message == message if not message_is_redundant(): __main__.log(self.name, "sending "+str(message)+ "to "+self.name +" worker") self.last_message = message self.queue.put(message) return True else: #print("not sending " +str(value)) return False
def __init__(self, login=None, password=None, token=None, captcha_handler=None, proxies=None, user_agent=None): self.login = login self.password = password self.token = token self.proxies = proxies self.user_agent = user_agent self.captcha_handler = captcha_handler log('vkauth\nlogin = {}\npassword = {}\ntoken = {}\nproxy = {}\nuser_agent = {}\ncaptcha_handler = {}' .format(login, password, token, proxies, user_agent, captcha_handler))
def auth(self): if self.token: try: self.vkapi = vk_api.VkApi(token=self.token, proxies=self.proxies, user_agent=self.user_agent, captcha_handler=self.captcha_handler, app_id=2685278, scope=1073737727) self.vkapi._auth_token(reauth=True) self.vkapi.method('account.setOffline') except Exception as E: log('Ошибка авторизации: {}\nАккаунт: {}:{}'.format( E, self.login, self.password)) return False elif self.login and self.password: try: self.vkapi = vk_api.VkApi(login=self.login, password=self.password, proxies=self.proxies, user_agent=self.user_agent, captcha_handler=self.captcha_handler, app_id=2685278, scope=1073737727) self.vkapi.auth(reauth=True) except Exception as E: log('Ошибка авторизации: {}\nАккаунт: {}:{}'.format( E, self.login, self.password)) return False return self.vkapi
def data_acq_from_rtl_power_fftw_rfi(__n__, start, stop_, check_devices, data, _sch_, sch_h, sch_m, sch_s, file_start_stop_n): out = [] if (_sch_ == True and __n__ == 0): sync_6.exec(sch_h, sch_m, sch_s) # __main__.log("Starting Acquisition at " , datetime.datetime.now()) for n in range(0, int(check_devices)): out.append( open( "./" + str(data["project"]) + "/logs/log_rlt_" + str(__n__) + ".txt", "w")) work = "rtl_power_fftw -f " + str(start) + ":" + str( stop_) + " -l -e " + str(data["time_for_obs"]) + " -t " + str( data["integration_time"] ) + " -m " + "./" + str( data["project"] ) + "/data/" + str(__n__) + " -g 4 -d " + str( n ) # , "rtl_power_fftw -f 92M:94M -e 10 -t 10 -m obs -g 0 -d 1"] __main__.log(work) p = subprocess.Popen(work, shell=True, stdout=out[n], stderr=out[n]) work_plot = "xterm -e python3 survey_1_with_save.py " + "./" + str( data["project"]) + "/data/ " + str(int(__n__) - 1) print(work_plot) r = subprocess.Popen(work_plot, shell=True, stdout=None, stderr=None) __main__.log("Acq Starting ") # at ", datetime.datetime.now()) __main__.log("Starting Acquisition at ", datetime.datetime.now()) # file_process_gene.write(str(p.pid)) # file_process_gene.write("\n") file_start_stop_n.write(str(__n__)) file_start_stop_n.write(" ") file_start_stop_n.write(str(start / 1e6)) file_start_stop_n.write(" ") file_start_stop_n.write(str(stop_ / 1e6)) file_start_stop_n.write("\n") p.wait() if (p.poll() != 0): p.kill() os.system("kill -9 " + str(p.pid + 1)) log("\n Killed", p.pid)
def __del__(self): log('>>>> Destructor for %s' % self.__class__.__name__) if self.camera: self.camera = None
def __del__(self): log('>>>> Destructor for %s' % self.__class__.__name__) gp.Camera.__del__(self)
from datetime import datetime from __main__ import log ##################################################### ##Check if backend library exist ##################################################### import pkgutil from __main__ import CWD if pkgutil.find_loader('cffi') is None: raise Exception('Please install cffi package.') cwd = os.getcwd() lib_dir = os.path.join(CWD, 'resources/lib/gphoto2cffi') lib = os.path.join(lib_dir, '_backend.so') if not os.path.isfile(lib): log(">>>> Building " + lib) os.chdir(lib_dir) os.system('python backend_build.py') os.chdir(CWD) if not os.path.isfile(lib): raise Exception('Cant build binary module.') from resources.lib.gphoto2cffi import gphoto2 as gp ##################################################### from .common import * ##make alias for exception BackendError = gp.errors.GPhoto2Error class BackendCamera(gp.Camera):
def __init__(self, *args, **kwargs): log('>>>> %s __init__' % self.__class__.__name__) self._type = None
def threaded_fun(motor): q = motor.queue current_direction = None current_throttle = 0 direction, target_throttle = ("forward", 0) bool_to_pin={ True : motor.forward_pin, False : motor.backward_pin } increment_time = motor.increment_time break_increment_time = motor.break_increment_time min_power = motor.min_power increment =motor.increment stopping_threshold = 0.1 last_increment = datetime.now() - timedelta(seconds=2) try: while True: if __main__.stop_application.isSet(): cond_log(motor, "exit") sys.exit() while not q.empty(): message_type, message_content = q.get() if message_type == message_type_throttle: direction, target_throttle = message_content divisor = 3 elif message_type == message_type_increment: increment = message_content elif message_type == message_type_power: if target_throttle>0: target_throttle= message_content divisor = 3 if direction is None: # wird übergeben, wenn gestoppt werden soll direction = current_direction current_direction_correct = current_direction is None or direction == current_direction direction_bool = direction_as_bool[direction] if not current_direction_correct: pin_to_stop = bool_to_pin[not direction_bool] __main__.set_pin_value(pin_to_stop, 0) current_direction = None current_throttle = 0 if target_throttle != 0: motor.running.set() else: motor.running.clear() current_direction = direction if target_throttle!=current_throttle: passed_seconds = (datetime.now() - last_increment).total_seconds() if current_throttle < target_throttle: if passed_seconds >=increment_time: if increment_time == 0: current_throttle = target_throttle else: #set the next biggest number which is still <=1 current_throttle = min(1, current_throttle + increment , target_throttle) current_throttle = max(current_throttle, min_power) #acceleration mode elif current_throttle > target_throttle: diff = current_throttle-target_throttle if passed_seconds >=break_increment_time: if break_increment_time == 0: current_throttle = target_throttle else: #stop if the remaining difference is < 0.1 if diff<=stopping_threshold: current_throttle = target_throttle else: current_throttle = max(current_throttle - (diff/divisor), 0, target_throttle) diff = current_throttle-target_throttle divisor= divisor-0.5 pin_to_change = bool_to_pin[direction_bool] if current_throttle!=__main__.get_pin_value(pin_to_change): __main__.set_pin_value(pin_to_change, current_throttle) last_increment = datetime.now() sleep(min(break_increment_time,increment_time,0.1 )) #sleep for a short time (min(increment time, 100ms)) except Exception as e: __main__.log(motor.name, "worker crashed") __main__.set_pin_value(motor.forward_pin, 0) __main__.set_pin_value(motor.backward_pin, 0) raise e
def cond_log(motor, log): __main__.log(motor.char, log)