-
Couldn't load subscription status.
- Fork 257
I get empty timers #7
Description
I'm using OSX Yosemite, and trying to time a script of mine in Python 3.4.1. I have 2 issues:
- if I don't run as sudo, I get an error when running kernprof
- even as sudo, the .lprof file comes up empty of times. Here's a dump of the screen (i deleted some sensitive lines)
$ sudo kernprof -lv ./emai-extractor.py
Wrote profile results to emai-extractor.py.lprof
Timer unit: 1e-06 s
Total time: 0 s
File: ./emai-extractor.py
Function: log_to_db at line 232
Line # Hits Time Per Hit % Time Line Contents
==============================================================
232 @profile
233 def log_to_db(data_in):
234 try:
235 log = {"datetime":datetime.datetime.now().strftime('%x %X'),
236 "sendername":data_in[0],
237 "senderemail":data_in[1][0],
238 "subject": data_in[2],
239 "recordscleaned": data_in[3],
240 "email_list": data_in[4],
241 "seconds_elapsed": data_in[5]
242 }
243 return db.general_log.insert(log)
244 except Exception as e:
245 logging.error("{} (exception: {})".format("failed to write general_log in DB", e))
Total time: 0 s
File: ./emai-extractor.py
Function: send_results at line 264
Line # Hits Time Per Hit % Time Line Contents
==============================================================
264 @profile
265 def send_results(to_inp, extra_message=None, file_inp=None):
266
267 recipients = [to_inp[1]] + CC + BCC
268 msg = MIMEMultipart('mixed')
269 msg['From'] = FROM_TEXT
270 msg['To'] = to_inp[1]
271 msg['Date'] = formatdate(localtime=True)
272 msg['Subject'] = 'Your cleaned up email list is ready!'
273
274 try:
275 fname = to_inp[0].split()[0]
276 except:
277 fname = ''
278
304
305 part1 = MIMEText(plain_text, 'plain')
306 part2 = MIMEText(html, 'html')
307
308 msg.attach(part2)
309 #msg.attach(part1)
310
311 attachment = MIMEBase('application', "octet-stream")
312 attachment.set_payload(file_inp.getvalue())
313 encoders.encode_base64(attachment)
314 attachment.add_header('Content-Disposition', 'attachment; filename="' +
315 datetime.datetime.now().strftime('%x') + ' EMAI-List.csv"')
316 msg.attach(attachment)
317
318 try:
319 server = smtplib.SMTP(IMAP_HOST, 587)
320 server.ehlo()
321 server.starttls()
322 server.login(LOGIN, PASSWORD)
323 server.sendmail(LOGIN, recipients, msg.as_string())
324 server.close()
325 logging.info('send_results(): Successfully sent mail!')
326 return True
327 except Exception as e:
328 logging.error("{} (exception: {})".format("send_results(): failed to send mail", e))
329 raise
Total time: 0 s
File: ./emai-extractor.py
Function: make_extra_msg at line 331
Line # Hits Time Per Hit % Time Line Contents
==============================================================
331 @profile
332 def make_extra_msg(senderemail, **kwargs):
333 try:
334 buf = []
335
336 pipe = []
337 pipe.append({'$match': {'senderemail': senderemail}})
338 pipe.append({'$group': {'_id':'$senderemail', 'RecordsCleaned':{'$sum':'$recordscleaned'}}})
339
340 res = db.general_log.aggregate(pipeline=pipe)
341 if res:
342 records_cleaned = res['result'][0]['RecordsCleaned']
343
344 s = db.detailed_log.find({'sender': senderemail}).distinct('email')
345 if s:
346 unique_emails = len(s)
347
348 #if records_cleaned and unique_emails:
349 # buf = "Stats for your account " + str(to_inp[1]) + ":
" \
350 # "- " + str(unique_emails) + " unique emails
" \
351 # "- " + str(records_cleaned) + " total emails" \
352 # "
"
353
354 if unique_emails:
355 txt = "- " + str(unique_emails) + " unique emails processed
"
356 buf.append(txt)
357
358 if records_cleaned:
359 txt = "- " + str(records_cleaned) + " total emails sent our way
"
360 buf.append(txt)
361
362 if kwargs is not None:
363 for key, value in kwargs.items():
364 txt = "- " + str(value) + " " + key + "
"
365 buf.append(txt)
366
367 if len(buf) > 0:
368 buf.append("")
369 txt = "Global info for your account " + str(senderemail) + ":
"
370 buf.insert(0, txt)
371
372 return ''.join(buf)
373 except Exception as e:
374 logging.error(e, exc_info=True)
375 return ''