Canceling HTTP requests through the Python SDK?

新規投稿

コメント

3件のコメント

  • Kamil Berdychowski

    Hello,

    unfortunately you cannot cancel any network request in Python SDK. You should be able to set a timeout though if that could help.

    I would like to understand why you need to cancel upload. or download requests. Can you tell me your use case maybe we could find a solution?

    One thing that comes to my mind is to use threads/processes for those requests and kill them if you need to cancel. 

    0
    コメントアクション パーマリンク
  • Michael Ratanapintha

    I would like to understand why you need to cancel upload. or download requests. Can you tell me your use case maybe we could find a solution?

    We are considering a change to let user to pause and resume Box uploads and downloads in progress through our app without exiting the app completely. When the user pushes the Pause button, we'd like the transfers to be terminated as quickly as possible. Setting a timeout in advance for each transfer would not work for this purpose.

    As an alternative, we could let the in-progress transfers complete and only block new ones, but that would not be as good an experience even if we tell our user what is happening.

    My idea is that we would then handle the user pushing the Resume button as follows:

    • For downloads, we would temporarily cache the part of the file content already downloaded on disk, so the transfer can be resumed in the middle by requesting a byte range.
    • For uploads, we already temporarily cache the whole file content on disk. For single-part uploads, we would restart the transfer from the beginning, while for chunked uploads, we would cache the upload session in memory and start only those chunks not yet fully uploaded, assuming the session has not since expired.

     

    One thing that comes to my mind is to use threads/processes for those requests and kill them if you need to cancel. 

    Dedicated threads for each request might work for us, but I'm worried what happens to our single app process if we start forcibly killing our own threads. I thought about forcibly closing just the TCP socket, which will at least leave the process in a consistently recoverable state, but even assuming we had access to the socket I saw that this might not always work on Windows. (https://stackoverflow.com/q/13809336 )

    0
    コメントアクション パーマリンク
  • Kamil Berdychowski

    We do not have any simple solution for this issue now... You can reach out to us using Github and maybe we can figure out something.

    0
    コメントアクション パーマリンク

投稿コメントは受け付けていません。