[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 05/12] simpletrace: Changed Analyzer class to become conte
|
From: |
Mads Ynddal |
|
Subject: |
Re: [PATCH v2 05/12] simpletrace: Changed Analyzer class to become context-manager |
|
Date: |
Mon, 15 May 2023 09:48:16 +0200 |
>
> Bearing in mind compatibility with existing simpletrace analysis
> scripts, how about the following default method implementations?
>
> def __enter__(self):
> self.begin()
>
> def __exit__(self, exc_type, exc_val, exc_tb):
> if exc_type is None:
> self.end()
> return False
>
> Now simpletrace.py can switch to using the context manager and new
> scripts can implement __enter__()/__exit__(), while old scripts continue
> to work.
I was considering the same, but I was worried about double initialization if
someone used both the context manager as well as calling .begin(). Should we add
a guard, that prohibits this?
Otherwise, we could also keep begin()/end() in Analyzer, and then make Analyzer2
a context manager?
>
> Please don't change the function signature since this is a public method
> and we should avoid breaking existing callers when possible.
>
> Instead of:
>
> with analyzer_class() as analyzer:
>
> we can use:
>
> with analyzer:
> ...
I didn't think of that. Let's do this, if we keep the context manager.
- Re: [PATCH v2 01/12] simpletrace: Improve parsing of sys.argv; fix files never closed., (continued)
[PATCH v2 04/12] simpletrace: update code for Python 3.11, Mads Ynddal, 2023/05/02
[PATCH v2 03/12] simpletrace: changed naming of edict and idtoname to improve readability, Mads Ynddal, 2023/05/02
[PATCH v2 05/12] simpletrace: Changed Analyzer class to become context-manager, Mads Ynddal, 2023/05/02
[PATCH v2 06/12] simpletrace: Simplify construction of tracing methods, Mads Ynddal, 2023/05/02
[PATCH v2 07/12] simpletrace: Improved error handling on struct unpack, Mads Ynddal, 2023/05/02
[PATCH v2 08/12] simpletrace: define exception and add handling, Mads Ynddal, 2023/05/02
[PATCH v2 09/12] simpletrace: Refactor to separate responsibilities, Mads Ynddal, 2023/05/02
[PATCH v2 10/12] MAINTAINERS: add maintainer of simpletrace.py, Mads Ynddal, 2023/05/02
[PATCH v2 11/12] scripts/analyse-locks-simpletrace.py: changed iteritems() to items(), Mads Ynddal, 2023/05/02
[PATCH v2 12/12] scripts/analyse-locks-simpletrace.py: reflect changes to process in simpletrace.py, Mads Ynddal, 2023/05/02
Re: [PATCH v2 00/12] simpletrace: refactor and general improvements, John Snow, 2023/05/03