Python Forum
Code running many times nad not just one?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code running many times nad not just one?
#1
hello,
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
Reply


Messages In This Thread
Code running many times nad not just one? - by korenron - Jul-17-2022, 07:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 714 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 432 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 568 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Different code execution times Wirbelwind94 4 797 Oct-06-2023, 12:30 PM
Last Post: snippsat
Question Running an action only between certain times alexbca 9 1,805 Mar-15-2023, 04:21 PM
Last Post: deanhystad
  Error while running code on VSC maiya 4 3,853 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,546 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 5,362 Feb-02-2022, 10:21 AM
Last Post: mcva
  Python keeps running the old version of the code quest 2 3,835 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  My python code is running very slow on millions of records shantanu97 7 2,648 Dec-28-2021, 11:02 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020