-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Refactor file handling #103
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
Conversation
|
I would also like to note that the function write_log_message still takes t2i as an argument, which it doesn't seem to utilise. (also I kinda lied with the commit message in 0f28663. |
|
Couldn't confirm if it works with GFPGAN. Speaking of which, is it intended that every after every generated image this warning comes up: "GFPGAN not initialized, it must be loaded via the --gfpgan argument"? |
|
No - sorry for that, fix is in main now, PR #101 |
|
Thanks for picking up these problems. This is a bad habit of mine from Perl programming, where filehandles are closed automatically as soon as they go out of scope.Will do some testing tomorrow morning and then merge. |
|
Using context managers in general should be pretty safe, but I would still advice to only spend as much time as necessary in them, at least in the case of file handling. |
|
@yunsaki The handling of --from_file by turning it into a list of lines almost works but not quite. The issue is that some users have requested the ability to read from standard input so that they can use the script in a pipeline or with named pipes. I tried this, and found that the current code has to wait until the EOF before it does the "\n" split. In the case of a pipeline this will cause deadlock. I think that it's actually OK not to create a file context for the from_file in this particular case because the script is going to end as soon as the EOF happens anyway. I've merged the other part of your commits and I'm reverting the from_file handling. If you have a better solution let me know. |
|
Alright, fair enough! I was the most unsure about that anyway. Might do some testing myself, but for now I don't have a better solution. |
|
@lstein Regarding refactoring; should I also implement the morphing dream main loop for the main branch? I think it has a few advantages, mostly in the sense that you have less indentations and don't need to do stuff like |
Looking at the dream.py I noticed that files tend to stay open for a long time. This is a bad practice with potential impact on system resources. If an open file is not handled correctly and an exception occurs the file will never be closed. This is why in my opinion the use of a context manager when dealing with files is a must in python. Furthermore I would argue that in a context manager you should only do what's absolutely necessary and then exit.
This is what I'm trying to do with this small merge request.
Please test if this still functions as intended.