Skip to content
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

Correct and check types on monitoring router and database processes #3572

Merged
merged 5 commits into from
Aug 14, 2024

Conversation

benclifford
Copy link
Collaborator

Description

Prior to this PR, the startup code for the monitoring router and database processes had type annotations on queues; but these types were not checked, and were incorrect - they were labelled process-local Queue instead of multiprocessing queues. This did not cause much trouble execution- and mypy-wise, as the interfaces of those two classes are similar enough, but it is confusing to read in a part of the codebase that is already confusing (that confusion is probably what lead to the incorrect annotations in the first place...)

They were not checked because the informal policy of "internal stuff is checked with mypy, external interfaces are checked with typeguard" works badly here:

The startup methods are launched using multiprocessing.Process, and function invocations are not type-checked by mypy across a multiprocessing Process constructor.

Changed Behaviour

This PR introduces typeguard decorators onto the router and database start methods so that this internal checking happens at runtime. This consequently reveals that the type annotations of these methods are incorrect, and so this PR makes those consequential changes.

Further, generic types (Queue[MessageType]) are not supported on multiprocessing.Queues before Python 3.12 - so those generic indices are removed from the type annotations. That is unfortunate and weakens in-process static verification - but they could be re-introduced after Parsl drops Python 3.11 support (around 2027 in the present informal support policy)

Type of change

  • Bug fix
  • Code maintenance/cleanup

they were introduced as `queue` module queues, but actually the values
(and the annotations used at the other end of the router_starter call)
are multiprocessing.Queue (subclasses...)

mypy does not typecheck this call... a later PR introduces typeguard here
(which detects this)

this hasn't caused execution problems - the APIs of the two queue types are close enough
- but it is incorrect when trying to understand how pieces of monitoring
communicate with each other.
@benclifford benclifford marked this pull request as draft August 8, 2024 09:29
…there are multiple Queue types floating around with very similar interfaces
benclifford added a commit that referenced this pull request Aug 8, 2024
This is in preparation for future type work in the monitoring
codebase (for example, see PR #3572).

This PR does not claim that the types it is moving around are
correct (and PR #3572 contains some instances where the types
are incorrect). It is a purely syntactic PR.

After this PR, $ git grep '# type:' parsl/monitoring/
returns two remaining comment style annotations, which are
'type: ignore' exclusions not specific types.
@benclifford
Copy link
Collaborator Author

waiting on #3573 for a bit of syntactic tidyup

benclifford added a commit that referenced this pull request Aug 10, 2024
This is in preparation for future type work in the monitoring
codebase (for example, see PR #3572).

This PR does not claim that the types it is moving around are
correct (and PR #3572 contains some instances where the types
are incorrect). It is a purely syntactic PR.

After this PR, $ git grep '# type:' parsl/monitoring/
returns two remaining comment style annotations, which are
'type: ignore' exclusions not specific types.
@benclifford benclifford marked this pull request as ready for review August 13, 2024 20:20
parsl/monitoring/db_manager.py Show resolved Hide resolved
@benclifford benclifford merged commit ffb3644 into master Aug 14, 2024
7 checks passed
@benclifford benclifford deleted the benc-monitoring-typeguard-types branch August 14, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants