Closed EvanKirshenbaum closed 8 months ago
This issue was referenced by the following commits before migration:
Threading issues aside (as they typically are in Python), it was all pretty straightforward. You can now say
set_default_units(s, ms, us)
with default_units(s, ms, V):
...
I also generalized the handling of --units
(and dimensional arguments in general) to allow UnitExpr
s rather than just Unit
s.
While working on the ability to specify default units to use (#167), I added,
Exerciser.set_default_units()
, which takes the units found on that argument (which may include several and be specified several times).While switching to platform-dispatched
Exerciser
s (#176), I realized that I had to specify default default units before adding args to theArgumentParer
so that help strings would have reasonable units for default values.For the former, it would be easier if I could simply have said something like
and then do the latter as simply
likely making that list a property of the
Exerciser
, which could be specified as a constructor parameter.The other problem with specifying the default defaults in
setup_task()
is that it would be nicer if it were localized, so that you could sayand have them reset back to what they were at the end.
Note that this won't really work right with multiple threads, since default units are a global notion. I could probably use
threading.local
to make a dimension's default units thread-local, but there doesn't seem to be any easy way to get the value to inherit its value from the parent thread (short of making sure that we use a subclass ofThread
that copies at leastthreading.get_ident()
into thread-local data for the new thread. This may be more mechanism than is warranted here,Also, it will probably still be astonishing if a callback is registered to a
Delayed
object and invoked in a different thread. Come to think of it, with futures, this whole thing will be weird, as the scope will likely be exited before the value is posted to the future.This clearly needs more thought.
Migrated from internal repository. Originally created by @EvanKirshenbaum on Jun 18, 2022 at 10:13 PM PDT. Closed on Jun 19, 2022 at 11:44 AM PDT.