nchint opened a new pull request, #30563:
URL: https://github.com/apache/beam/pull/30563

   ## Background
   Suppose you have the following script
   ```python
   import argparse
   from apache_beam.options.pipeline_options import PipelineOptions
   
   PipelineOptions()
   assert False
   ```
   
   Here's is the behavior when running this script
   ```bash
   $ python3 test.py 
   Traceback (most recent call last):
     File "/Users/chintala/./test.py", line 5, in <module>
       assert False
   AssertionError
   $ python3 test.py  -h
   usage: test.py [-h]
   
   options:
     -h, --help  show this help message and exit
   ```
   
   During `__init__` of `PipelineOptions` we make a call to `parse_known_args` 
with the `self._flags` field. The behavior of `parse_known_args` is if it is 
given `None` as an argument it will use `sys.argv` for the argument list and 
parse those. If `-h` is within the argument list `parse_known_args` will print 
the help statement and then exit the python process.
   
   The ultimately means that if you run a python script that defines a 
`PipelineOptions` at top level and supply `-h` in the command line arguments 
your program will exist upon instantiating `PipelineOptions` which is undesired 
behavior.
   
   ## Solution
   Instead of defaults `self._flags` to `None` we set it to an empty list 
instead. This means when we call `parse_known_args` it will never read from 
`sys.argv`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to