繁体   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