Conversation
There was a problem hiding this comment.
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
- 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.
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).
|
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.