Sultan.load() vs Sultan()
metaperl opened this issue · 2 comments
In Streaming Results from a Command we see:
with Sultan.load() as s:
result = s.yum('install', '-y', 'postgresql').run(streaming=True)
while True:
# if full output is needed, read the pipes one last time
# after `is_complete == True` to avoid a race condition
complete = result.is_complete
for line in result.stdout:
print(line)
for line in result.stderr:
print(line)
if complete:
break
time.sleep(1)
My question is: how different would this code be if Sultan.load()
were replaced with Sultan()
.
is load
documented anywhere? Is Sultan()
documented anywhere?
Hey @metaperl ... the documentation for load()
is here: https://sultan.readthedocs.io/en/latest/sultan-examples.html#example-2-sultan-with-context-management
All the examples there use the load()
method.
If you were to use it with the constructor Sultan()
, you can pass these contexts in with the context
keyword argument, which is a dictionary. Sultan uses these determine the right type of bash command to generate based on the parameters you provide, so using load()
is the right way to do it. I didn't document using Sultan()
constructor because of this reason, since it is not the recommended way of doing so.