tomgross / pcloud

A Python implementation of the pCloud API
MIT License
93 stars 28 forks source link

async file upload #84

Open MrWillTurner opened 11 months ago

MrWillTurner commented 11 months ago

Hi. I am trying to use the module asyncio to asynchronously upload files to my pcloud folder but it always blocks waits for the upload to be terminate before doing the next line

Do you have any idea of what I'm doing wrong ?


from dotenv import load_dotenv
import os
import asyncio

async def call_this(connection,file):
    await uploadfile(connection,file)

async def uploadfile(connection,file):
    await connection.uploadfile(files = file)
    print("done")

load_dotenv()

pcloud_user = os.environ.get("PCLOUD_USER")
pcloud_password = os.environ.get("PCLOUD_PASSWORD")

connection = PyCloud(pcloud_user, pcloud_password)

asyncio.run(call_this(connection,["test.png","test2.png"]))
tomgross commented 10 months ago

Hi @MrWillTurner thanks for your report. The PCloud library uses the synchronous request-library. There is an asynchronous one. I assume there is some blocking/unblocking magic involved, which prevents your code example from working.

If you interested in an async version of pCloud you have several options:

Implement it yourself and submit a pull request.
Wait until I have time and interest to implement it.
Pay me (or someone else) to implement it. My contact details are on my homepage: https://tomgross.github.io/

If you use and ❤️ my software, consider buying me a coffee ☕ https://www.paypal.com/paypalme/tomgross42

mokko commented 10 months ago

In the video below Arjan recommends using request with asyncio.to_thread. Might work here too. https://www.youtube.com/watch?v=GpqAQxH1Afc

Does that help?