簡體   English   中英

Windows批處理文件Infinite Loop在運行Python文件時掛起

[英]Windows batch file Infinite Loop hang while running Python file

我有一個非常簡單的Windows批處理文件,該文件應運行Python,等待5秒鍾,回顯搜索,循環。 Python文件正在檢查我的電子郵件,然后創建文件或刪除它們,然后在條件適合我進行交易時通過電子郵件發送給我。 它工作的很好,但是一夜之間我醒來看到它停滯了。 如果按回車,它將再次啟動並運行一段時間。

批處理代碼為

:loop
timeout 5

"C:\Anaconda3\python.exe" "TValert.py"

echo "Scan Complete"

goto loop

和python代碼是

import imaplib,email,time
import smtplib
import os.path
from os import path
#mail imap
user = 'Trader@gmail.com'
pwd = 'password'
imap_url = 'imap.gmail.com'
con = imaplib.IMAP4_SSL (imap_url)
con.login(user,pwd)
con.select('INBOX')


def deleteEmail(user, pwd, IMAP):

    typ, data = con.search(None, 'ALL')
    for num in data[0].split():
        con.store(num, '+FLAGS', r'(\Deleted)')
        con.expunge()



print("Scanning Email....")
time.sleep(1.5)
result, no = con.search(None,'(FROM "god" SUBJECT "Come Home")')
result, long = con.search(None,'(FROM "tradingview" SUBJECT "Rosie Long")')
result, short = con.search(None,'(FROM "tradingview" SUBJECT "Rosie Short")')
result, close_long = con.search(None,'(FROM "tradingview" SUBJECT "Rosie Close Long")')
result, close_short = con.search(None,'(FROM "tradingview" SUBJECT "Rosie Close Short")')
result, TwoRiskOff = con.search(None,'(FROM "tradingview" SUBJECT "$2 Risk Off")')    
result, NineRiskOff = con.search(None,'(FROM "tradingview" SUBJECT "$9 Risk Off")')    
result, TwoWhite = con.search(None,'(FROM "tradingview" SUBJECT "$2 White")')    
result, NineWhite = con.search(None,'(FROM "tradingview" SUBJECT "$9 White")')      
result, TwoBlack = con.search(None,'(FROM "tradingview" SUBJECT "$2 Black")')    
result, NineBlack = con.search(None,'(FROM "tradingview" SUBJECT "$9 Black")')      

if long != no:
    if path.exists("Long.txt"):
        mail=smtplib.SMTP('smtp.gmail.com',587)
        mail.ehlo()
        mail.starttls()
        mail.login(user,pwd)
        message = 'Subject: {}\n\n{}'.format("ERROR DUPLICATE LONG SIGNAL","ERROR DUPLICATE LONG SIGNAL" )    
        mail.sendmail(user,"2062348485@mms.att.net",message)
        mail.close

    else:
        if path.exists("Short.txt"):
            os.remove("Short.txt")
            mail=smtplib.SMTP('smtp.gmail.com',587)
            mail.ehlo()
            mail.starttls()
            mail.login(user,pwd)
            message = 'Subject: {}\n\n{}'.format("Close Long Position","Close Long Position" )    
            mail.sendmail(user,"2062348485@mms.att.net",message)
            mail.close

        else:
            if path.exists("TwoWhite.txt"):
                if path.exists("NineWhite.txt"):
                    open("Long.txt","w+")
                    mail=smtplib.SMTP('smtp.gmail.com',587)
                    mail.ehlo()
                    mail.starttls()
                    mail.login(user,pwd)
                    message = 'Subject: {}\n\n{}'.format("BUY NOW!", "BUY NOW!")    
                    mail.sendmail(user,"2062348485@mms.att.net",message)
                    mail.close
                else:
                    print("No Correlation")
            else:
                print("No Correlation")





if short != no:
    if path.exists("Short.txt"):
        mail=smtplib.SMTP('smtp.gmail.com',587)
        mail.ehlo()
        mail.starttls()
        mail.login(user,pwd)
        message = 'Subject: {}\n\n{}'.format("ERROR DUPLICATE SHORT SIGNAL","ERROR DUPLICATE SHORT SIGNAL" )    
        mail.sendmail(user,"2062348485@mms.att.net",message)
        mail.close

    else:
        if path.exists("Long.txt"):
            os.remove("Long.txt")
            mail=smtplib.SMTP('smtp.gmail.com',587)
            mail.ehlo()
            mail.starttls()
            mail.login(user,pwd)
            message = 'Subject: {}\n\n{}'.format("Close Long Position","Close Long Position" )    
            mail.sendmail(user,"2062348485@mms.att.net",message)
            mail.close

        else:
            if path.exists("TwoBlack.txt"):
                if path.exists("NineBlack.txt"):
                    open("Short.txt","w+")
                    mail=smtplib.SMTP('smtp.gmail.com',587)
                    mail.ehlo()
                    mail.starttls()
                    mail.login(user,pwd)
                    message = 'Subject: {}\n\n{}'.format("SELL NOW!", "SELL NOW!")    
                    mail.sendmail(user,"2062348485@mms.att.net",message)
                    mail.close
                else:
                    print("No Correlation")
            else:
                print("No Correlation")





if TwoRiskOff !=no:
    try:
        if path.exists("TwoBlack.txt"):
            os.remove("TwoBlack.txt")
        if path.exists("TwoWhite.txt"):
            os.remove("TwoWhite.txt")
    except:
        print("Error While Running Two Risk Off")

if NineRiskOff !=no:
    try:
        if path.exists("NineBlack.txt"):
            os.remove("NineBlack.txt")
        if path.exists("NineWhite.txt"):
            os.remove("NineWhite.txt")
    except:
        print("Error While Running Two White")

if TwoWhite !=no:
    try:
        open("TwoWhite.txt","w+")
        if path.exists("TwoBlack.txt"):
            os.remove("TwoBlack.txt")
    except:
        print("Error While running Two White")


if TwoBlack !=no:
    try:
        open("TwoBlack.txt","w+")
        if path.exists("TwoWhite.txt"):
            os.remove("TwoWhite.txt")    
    except:
        print("Error While running Two Black")

if NineWhite !=no:
    try:
        open("NineWhite.txt","w+")
        if path.exists("NineBlack.txt"):
            os.remove("NineBlack.txt")
    except:
        print("Error While running Nine White")

if NineBlack !=no:
    try:
        open("NineBlack.txt","w+")  
        if path.exists("NineWhite.txt"):
            os.remove("NineWhite.txt")
    except:
        print("Error While running Nine Black") 

deleteEmail(user,pwd,con)


exit()


今天我和我的一個朋友聊天,他指示我通過Powershell運行python文件,到目前為止,它運行良好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM