'How to specify Faust arguments when using app.main()
Currently I run several workers using the command line with the following syntax:
faust -A <filepath>:app -D <data-log-path> worker -l info -p 6066
and it works fine. But it seems it would be much nicer to run the .py
file and have the log-level, data-dir, and port all specified in the:
if __name__ == '__main__':
app.main()
style. I can't seem to figure out how to add any of the arguments/options listed above to either the defining of the app object (app = faust.App()
) or the app.main()
funtion.
I will just add that I'm not sure it's worth doing anyway, as I plan to run all the workers from a shell script. It was just going to be a way to ensure all workers are given a unique port to run on, but i guess i can hard code that into the shell scrip if required.
Solution 1:[1]
The most common way of achieving this is using sys.argv
. There's an example of this in the tabletest.py example:
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
sys.argv.extend(['worker', '-l', 'info'])
app.main()
Before continuing, I suggest looking at the worker command line options in faust.cli.worker.
Assuming you'd like to hard-code your values in a script, what you'd need to do is:
if __name__ == '__main__':
import sys
sys.argv = [__file__, 'worker', '-l', 'info', '-p', '6066', '-f', '<data-log-path>']
app.main()
With this, you can run yourscript.py
without needing to specify options.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | wbarnha |