Closed drscotthawley closed 8 months ago
Seems the behavior is not unique to inspect
. It seems that Fire will unexpectedly print even if you just access locals()
. This is a side effect I'd love to disable.
Minimal example:
import fire
def my_routine(arg1, arg2):
return locals()
if __name__ == '__main__':
vals = fire.Fire(my_routine) # this produces unwanted print statements
print("vals = ",vals)
Output includes not just the "vals = " line but two additional variable outputs that occur when locals()
gets called while using Fire()
:
arg1: dummy_arg1
arg2: dummy_arg2
vals = {'arg1': 'dummy_arg1', 'arg2': 'dummy_arg2'}
It's no so much the printing that's the problem per se, it's the fact that it blocks execution and waits for the user to press enter (if it prints more than a page of variables) that's the main problem.
Fire displays the returned object on completion by default. To disable this, you can use:
noprint = lambda _: None
fire.Fire(my_routine, serialize=noprint)
Awesome! Thank you very much! Closing.
Hi, when I use
fire.Fire()
, I find that it's printing variable info every time I useinspect
, including pausing at every page boundary. I'd like to disable this unexpected printing behavior. Simple example code:Expected output from running
python test.py dummy_arg1 dummy_arg2
is this:but instead I see this:
Those printed lines that start with
arg1: dummy_arg1
throughc: [3,4,5]
are not in my code. SomehowFire()
is triggering print statements, unbidden. If there are many local variables, it even blocks execution at every printed-page boundary until the user manually presses Enter.I don't have
--verbose
or--trace
enabled. (Meaning verbose should be False unless it's set, right? or perhaps I need to say--verbose False
?)How do we disable this unbidden printing(+paging) behavior? Didn't see this mentioned in the Fire Guide.
Info:
Thanks!