I’ve been trying to get this to work for over a day now. My main problem is I haven’t found much on fsspec
or rich.progress.Progress
on the net, or here on stackoverflow.com.
I’ve walked through every line while bebugging and every line is being executed as it should, but it isn’t generating any output to the console.
This next part is a complete guess to why this isn’t working.
rich.progress.Progress
is directly linking to the console, it is how it is hiding the cursor during execution, and I’m guessing that rich is generating to a console that isn’t being shown, cause fsspec.callbacks.Callback
is being ran asynchronously.
Source:
import contextlib
import fsspec.callbacks as callbacks
import rich.progress as progress
import rich.style as style
import pydrive2.fs
class RichCallback(callbacks.Callback):
def __init__(self, *args, **kwargs):
self._progress = progress.Progress(
progress.BarColumn(
bar_width = 100,
style = style.Style(
color = style.Color.from_rgb(
red = 255,
green = 0,
blue = 0
)
),
complete_style = style.Style(
color = style.Color.from_rgb(
red = 0,
green = 255,
blue = 0
)
)
),
"[progress.percentage]",
progress.DownloadColumn(),
progress.TransferSpeedColumn(),
'eta',
progress.TimeRemainingColumn()
)
self._task = None
super(RichCallback, self).__init__(*args, **kwargs)
def call(self, *args, **kwargs):
if self._task is None:
self._task = self._progress.add_task(description = '', total = self.size)
self._progress.update(task_id = self._task, completed = self.value)
def close(self):
if self._progress is not None:
self._progress.stop()
def __del__(self):
return self.close()
if __name__ == '__main__':
with contextlib.suppress(KeyboardInterrupt):
fs = pydrive2.fs.GDriveFileSystem(
'root',
client_id = '261913292331-qm2p4sf5bsi8sp9p1lrtkor25vm3m4g5.apps.googleusercontent.com',
client_secret="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",
profile="phpjunkie",
client_json_file_path="keyfile.json"
)
lpath = r''
rpath=""
with RichCallback() as callback:
fs.put_file(
lpath = lpath,
rpath = rpath,
callback = callback
)
This is an example of rich.progress.Progress and it works just fine. It doesn’t do anything except iterate over a for loop.
total = 200000000
with Progress(
TextColumn("[bold blue]{task.description}", justify = "right"),
BarColumn(
bar_width = 100,
style = Style(
color = Color.from_rgb(
red = 255,
green = 0,
blue = 0
)
),
complete_style = Style(
color = Color.from_rgb(
red = 0,
green = 255,
blue = 0
)
)
),
"[progress.percentage]",
DownloadColumn(),
TransferSpeedColumn(),
'eta',
TimeRemainingColumn()
) as progress:
task = progress.add_task(description = '', total = total)
for i in range(1, total + 1, 960000):
progress.update(task_id = task, completed = i)
api.Sleep(100)
You need to sign in to view this answers
Leave feedback about this