tornadoweb / tornadoweb/tornado
Adding (user) callback to normalize option value ?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Description
Here is my usecase: I create a tornado HTTPServer and its Application. They are configured with options both from parse_command_line and parse_config_file. For instance I define the option:
options.define(
'a-file-to-load',
type=str,
metavar='path',
help='This file will be loaded later in the application')
I parse my config, initialize the app, start the HTTPServer; everything is going well. Then when everything is OK I daemonize my process. One of the operation is to change the current working directory to /. But my a-file-to-load option is maybe a relative path. When I try to open it later, it fails.
My concern is here to normalize my option value after parsing. I did try to put a callback:
def normalize_callback(path):
options.a_file_to_load = os.path.abspath(path)
But it loops recursively on the callback (because _Option#set method is actually calling the callback as well).
My question is: can we add a callback to normalize the option value or can we pass a flag to callback to avoid recursion ? Otherwise do you have any good idea to handle this use case ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the _Option#set method and the paths used by options.define, parse_command_line, and parse_config_file. Trace how callbacks are invoked and how option values are assigned; done requires a decided, non-recursive normalization API that covers the described daemonization case and has its behavior verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100