-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve config deprecated upgrade log, etc #2854
Improve config deprecated upgrade log, etc #2854
Conversation
396d01c
to
4d629bc
Compare
(Not done yet.) |
See #1136. |
8b01653
to
80cfabf
Compare
@@ -1023,15 +1016,11 @@ def upgrade_pickle_to_json(self): | |||
else: | |||
args.append(cell) | |||
except (EOFError, TypeError, LookupError, ValueError): | |||
n_skips += 1 # skip bad rows | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were diagnostics for my own use when I wrote these upgrade methods.
They are mostly upgrade methods for restarting Cylc 6 suites in Cylc 7. We should not have much usage for them any more. Happy to revert and leave them alone but aim to remove them for Cylc 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's OK to remove them, as they were for testing/debugging only.
When we go full Python3, this - and other try/catch with similar pattern - can go away too with
with ignored(EOFError, TypeError, LookupError, ValueError):
for col, cell in zip(cols, row):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool indeed, I dislike except: pass
type statements (although I guess that's probably what this is doing underneath). I've been stuck with Python 2.6 for too long, need to get up to date.
sys.stderr.write( | ||
"fork #1 failed: %d (%s)\n" % (exc.errno, exc.strerror)) | ||
sys.exit(1) | ||
except OSError as exc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Python 3 readiness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏 thanks!!!
|
||
# reset umask, octal | ||
os.umask(022) | ||
os.umask(0o22) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Python 3 readiness.
80cfabf
to
88352a1
Compare
sys.exit(1) | ||
|
||
LOG.exception(exc2) | ||
raise exc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have an unknown Exception
. I think it is best if we re-raise it regardless of debug mode or log level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed Cylc is a little too fond of swallowing exceptions, particularly in cylc.config
.
lib/cylc/suite_srv_files_mgr.py
Outdated
# Remove symlink to the original suite. | ||
os.unlink(target) | ||
|
||
# Create symlink to the suite, if it doesn't already exist. | ||
if source != orig_source: | ||
os.symlink(source, target) | ||
|
||
print 'REGISTERED %s -> %s' % (reg, source) | ||
return reg | ||
return reg, source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This increases the purity of the method:
- Let it return all the useful variables to the caller.
- Let the caller decide if it needs to print any diagnostics.
- I would have wanted to remove the remaining logging logic if there is an easy way to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first impression was a bit of confusion. Why should we return source
, being it is an argument
for the function in the first place (which can be a code smell, or a feature or per design [e.g. builder pattern]).
Then I realized reg
is also a parameter. I think the code would be simpler to read if it did not return anything. Simply received parameters, registered suites and threw exceptions if any error occurred.
The caller of the function would be responsible for choosing the right value for reg
(i.e. if you don't have one, use os.path.basename(os.getcwd())
), and for source
.
This way, IMO, it would be easier to i) read and understand what the function does, ii) write tests, iii) maintain the code.
The iii may not be clear right now, but if we decide to adopt other strategies for choosing the possible default value for reg
or source
(e.g. say we have AWS and decide to use an environment variable for the default values?) we wouldn't have to touch this function, but move the logic to the caller.
So I agree with the change, for the current design of the function 😬 but later will try to come up with alternatives (unless I'm missing something that prevents other designs).
@@ -524,8 +524,7 @@ def _event_email_callback(self, proc_ctx, schd_ctx): | |||
else: | |||
self.event_timers[id_key].unset_waiting() | |||
except KeyError as exc: | |||
if cylc.flags.debug: | |||
LOG.exception(exc) | |||
LOG.exception(exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KeyError
used to happen quite often because we were relying on the task proxy being in the pool. In the current logic, this is no longer the case - as the event handler contexts are now kept in a dict independent of their original task proxies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if an exception is caught, we want to log it, regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info!
Done, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request had - besides the great work on better logging - some nice improvements for Python3 in exception handling, new comments in the code, some extra comments in GitHub's UI explaining the rationale behind the change in the pull request and some history of the code 👏
+1, LGTM, and big thanks!
@@ -1023,15 +1016,11 @@ def upgrade_pickle_to_json(self): | |||
else: | |||
args.append(cell) | |||
except (EOFError, TypeError, LookupError, ValueError): | |||
n_skips += 1 # skip bad rows | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool indeed, I dislike except: pass
type statements (although I guess that's probably what this is doing underneath). I've been stuck with Python 2.6 for too long, need to get up to date.
sys.exit(1) | ||
|
||
LOG.exception(exc2) | ||
raise exc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed Cylc is a little too fond of swallowing exceptions, particularly in cylc.config
.
Use DEBUG level for site files - users may not be able to fix them easily. Use WARNING level for all other files to better alert users. Remove more print and sys.std*.write * Where possible, use logging instead of print or sys.std*.write. * Remove unnecessary diagnostics and some debug flag check in favour of simple logging. * Exit with error message instead of print error then exit 1. Use 0o syntax for octal literal.
a0460ed
to
64b4d9e
Compare
Use DEBUG level for site files - users may not be able to fix them
easily. Use WARNING level for all other files to better alert users.
Remove more
print
orsys.std*.write
statements by converting them to uselogging
.print
error thensys.exit(1)
.