Jul-17-2022, 07:56 AM
hello,
something isn't understaood for me
I have this code :
shouldn't it run only once? this part is before the loop \ while
something isn't understaood for me
I have this code :
my_os = platform.system() print("OS in my system : ", my_os) if my_os == 'Windows': UploadDirectory = r'r"C:\\Test\\FilesToUpload\\' DeviceError= r"C:\\Test\\logs\\DeviceError.txt" MysqlError_Log = r"C:\\Test\\logs\\MysqlErrorLog.txt" MysqlSuccess_Log = r"C:\\Test\\logs\\MysqlSuccessLog.txt" DeviceSuccess= r"C:\\Test\\logs\\DeviceSuccess.log" logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', handlers=[RotatingFileHandler(filename=r'C:\\Test\\logs\\GetConst.log', mode='w')]) else: logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', handlers=[RotatingFileHandler(filename='/home/pi/logs/GetConst.log', mode='w')]) UploadDirectory = r'/home/pi/FilesToUpload/' DeviceError= "/home/pi/logs/DeviceError.txt" MysqlError_Log = "/home/pi/logs/MysqlErrorLog.txt" MysqlSuccess_Log = "/home/pi/logs/MysqlSuccessLog.txt" DeviceSuccess= "/home/pi/logs/DeviceSuccess.log" print('will clear all logs files') open(DeviceError, 'w').close() open(MysqlSuccess_Log, 'w').close() open(MysqlError_Log, 'w').close() open(DeviceSuccess, 'w').close() def getListFromMysql(): . . def function2(): . . if __name__ == '__main__': while 1: logging.info('Start running now') StartTime = datetime.datetime.now() print(str(StartTime) + ' Start Time of the program') MysqlDataList = getListFromMysql() try: with Pool(50) as p: List1 = p.map(function2, MysqlDataList) except Exception as e: print('Pool Error') print(e) EndTime = datetime.datetime.now() print('Total : ' + str(len(MysqlDataList)) + ' Devices') print(str(EndTime) + ' End Time of the program')when I run it in Pycharm it run the first part (before the while) many times, why ?
shouldn't it run only once? this part is before the loop \ while
OS in my system : Windows 1 will clear all logs files 2022-07-17 10:51:23.076256 Start Time of the program There are 3 Devices! OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files OS in my system : Windows 1 will clear all logs files Process finished with exit code -1