-
Notifications
You must be signed in to change notification settings - Fork 33
Fix the processor instance caching #987
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
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 is problematic:
- obviously, you forgot the other branch of the conditional (with profiling enabled, there's also a
processor.process()...) - your cached processors were all constructed with a non-null
workspaceargument, which causes them tochdirinto that:
core/ocrd/ocrd/processor/base.py
Lines 140 to 142 in 9ae6ddf
if self.workspace: self.old_pwd = getcwd() os.chdir(self.workspace.directory) - your current
workspace.directorymight not be an absolute path; so it would become relative to the previous workspace, not to CWD of the caller
So either you rebase to the processor.old_pwd, or pass workspace=None when caching, or resolve to absolute here before calling.
(BTW, in my PR I also moved the chdir to run_api alone, which would be the equivalent of the second option I mentioned.)
|
@bertsky, thanks for the feedback, and insight. Indeed, I missed the first
Oh. Why is this so? This feels a bit odd to what I would have expected - the CWD of the caller once the process() method exits. I will check in more detail how to get the desired behavior without changing the current logic much. |
Because your |
bertsky
left a comment
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.
Looks better now, but I still feel we should not pass workspace to get_processor at all.
(The processor constructor will chdir into that, so if it is a relative path, then our own subsequent chdir on L98 will not work.)
Better to omit the workspace kwarg (so None gets passed to the constructor), and then set processor.workspace = workspace afterwards (next to the chdir on L98).
bertsky
left a comment
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.
LGTM – thanks!
|
Should we extensively use |
Not without adapting |
In #972, I missed using the context switch required for the cached processor instances to work correctly. Now I am able to reuse cached instances. According to my observations and testing, for both cached and non-cached, that additional line has no side effects.