Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Feature/ct 194/memcached uploader urls #192

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

lawschlosser
Copy link
Contributor

No description provided.

Copy link
Contributor

@WMDConductor WMDConductor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - with small exception catching nit + Codacy considerations assumed sorted out.

assert type(char_count) == int, "char_count must be int. Got: %r (%s)" % (char_count, type(char_count))
try:
s_str = pformat(object_) if pretty else str(object_)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we could make this: catch explicit:

except (ValueError, TypeError):

@@ -7,6 +7,7 @@
import multiprocessing
import os
import platform
from pprint import pformat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from x import y go after import x statements.

eg. this is what isort gives me:

import base64
import datetime
import functools
import hashlib
import json
import logging
import multiprocessing
import os
import platform
import random
import signal
import subprocess
import sys
import time
import traceback
from pprint import pformat

import yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably decide as a team on how we want to sort imports. I haven't seen much in google style guide or pep8 (aside from grouping imports by builtin, thirdparty, internal).
Personally, I sort imports alphabetically, considering the uppermost namespace (parent packages) when evaluating order. I don't distinguish/consider whether it's a from vs import. I find that it makes it easier for me to look something up, if there is one continuous alphabetical ordering, rather than having multiple sections of their own ordering. But we're all weird humans, thinking in weird ways.

also, I noticed that isort has several different options that make dramatic differences (--no-sections, --order-by-type, --project, --thirdparty , etc). Might be worth playing around with these to find a workflow something that we all like (dislike ;) ).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, let's make this a team decision.

'''
Return a string representation of the given object, shortened to the given
char_count. This can be useful when printing/logging out data for debugging
purposes, but don't want an overwhelming wall of text to troll through.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/troll/scroll/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intended spelling. But after reading this: https://english.stackexchange.com/questions/122627/trawling-through-or-trolling-through
....I'm wondering if I should just change it to your recommendation (English is so hard!)

try:
logger.info(self.manager.worker_queue_status_text())
logger.info(self.upload_status_text())
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except: would also work as a catch-all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been going back and forth on this recently (due to recent revelations that I'm somewhat embarrassed about). And coincidentally, this module makes for the perfect example!
As much as I have loved to catch all exceptions by simply not listing any specific types (when deemed appropriate), I didn't realize there was a subtle difference in doing so vs explicitly catching the Exception class. See https://stackoverflow.com/questions/730764/how-to-properly-ignore-exceptions

Usually it doesn't matter if we "catch all" exception, but because this module's application (the uploader), is a long running (daemon) process, that can only be stopped via killing it (ctrl-c, sigint, sigterm, etc), we have to be thoughtful to not disrupt any logic in the uploader that is expecting to encounter ctrl-c (KeyboardInterrupt).
Here's a great example of how you can unintentionally make trouble : https://fman.io/blog/an-inescapable-while-loop-in-python/

side note: here's an interesting diagram/hierarchy of pythons exception classes (as well as general good reading): https://airbrake.io/blog/python-exception-handling/class-hierarchy

def stop_work(self):
global WORKING
WORKING = False # stop any new jobs from being created
self.drain_queues() # clear out any jobs in queue
self.kill_workers() # kill all threads
self.kill_metricstore()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the method to kill_metric_store for consistency with the above variable self.metric_store?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, makes sense

return (queue.get_nowait())
except Queue.Empty:
return
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to except:.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lawschlosser lawschlosser force-pushed the feature/CT-194/memcached-uploader-urls branch from 857329c to fc0766e Compare April 13, 2018 23:00
@AtomicConductor AtomicConductor deleted a comment Apr 13, 2018
@AtomicConductor AtomicConductor deleted a comment Apr 13, 2018
@AtomicConductor AtomicConductor deleted a comment Apr 13, 2018
@lawschlosser lawschlosser force-pushed the feature/CT-194/memcached-uploader-urls branch from fc0766e to 4a1f334 Compare April 14, 2018 03:22
@AtomicConductor AtomicConductor deleted a comment Apr 14, 2018
@@ -7,6 +7,7 @@
import multiprocessing
import os
import platform
from pprint import pformat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, let's make this a team decision.

@lawschlosser lawschlosser force-pushed the feature/CT-194/memcached-uploader-urls branch from 4a1f334 to 03a1f1d Compare April 25, 2018 20:05
@AtomicConductor AtomicConductor deleted a comment Apr 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants