How to find if a file has been downloaded completely using python?











up vote
-1
down vote

favorite












We are having a python script which automates the batch processing of time-series image data downloaded from the internet. The current script requires all data to be downloaded before execution. This consumes more time. We want to modify the script by writing a scheduler which will call the script whenever a single data is completely downloaded. How to find that a file has been downloaded completely using python?










share|improve this question
























  • Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
    – Charles Landau
    Nov 11 at 6:36










  • The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
    – Mark Setchell
    Nov 11 at 9:31















up vote
-1
down vote

favorite












We are having a python script which automates the batch processing of time-series image data downloaded from the internet. The current script requires all data to be downloaded before execution. This consumes more time. We want to modify the script by writing a scheduler which will call the script whenever a single data is completely downloaded. How to find that a file has been downloaded completely using python?










share|improve this question
























  • Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
    – Charles Landau
    Nov 11 at 6:36










  • The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
    – Mark Setchell
    Nov 11 at 9:31













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











We are having a python script which automates the batch processing of time-series image data downloaded from the internet. The current script requires all data to be downloaded before execution. This consumes more time. We want to modify the script by writing a scheduler which will call the script whenever a single data is completely downloaded. How to find that a file has been downloaded completely using python?










share|improve this question















We are having a python script which automates the batch processing of time-series image data downloaded from the internet. The current script requires all data to be downloaded before execution. This consumes more time. We want to modify the script by writing a scheduler which will call the script whenever a single data is completely downloaded. How to find that a file has been downloaded completely using python?







python image image-processing scheduler






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 7:08









Sniffer

6321721




6321721










asked Nov 11 at 5:21









Girish Kumar

34




34












  • Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
    – Charles Landau
    Nov 11 at 6:36










  • The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
    – Mark Setchell
    Nov 11 at 9:31


















  • Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
    – Charles Landau
    Nov 11 at 6:36










  • The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
    – Mark Setchell
    Nov 11 at 9:31
















Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
– Charles Landau
Nov 11 at 6:36




Welcome to Stackoverflow. Could you show us what you've done so far? Any specific problems/errors you've come across?
– Charles Landau
Nov 11 at 6:36












The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
– Mark Setchell
Nov 11 at 9:31




The normal way to do this is to download the file with a temporary, sentinel extension, e.g. image.png.download and then rename to image.png when it is complete. That way you can identify downloads that are in progress, complete, or stalled.
– Mark Setchell
Nov 11 at 9:31












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










If you download the file with Python, then you can just do the image processing operation after the file download operation finishes. An example using requests:



import requests
import mymodule # The module containing your custom image-processing function

for img in ("foo.png", "bar.png", "baz.png"):
response = requests.get("http://www.example.com/" + img)
image_bytes = response.content
mymodule.process_image(image_bytes)


However, with the sequential approach above you will be spending a lot of time waiting for responses from the remote server. To make this faster, you can download and process multiple files at once using aysncio and aiohttp. There's a good introduction to downloading files this way in Paweł Miech's blog post Making 1 million requests with python-aiohttp. The code you need will look something like the example at the bottom of that blog post (the one with the semaphore).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246062%2fhow-to-find-if-a-file-has-been-downloaded-completely-using-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    If you download the file with Python, then you can just do the image processing operation after the file download operation finishes. An example using requests:



    import requests
    import mymodule # The module containing your custom image-processing function

    for img in ("foo.png", "bar.png", "baz.png"):
    response = requests.get("http://www.example.com/" + img)
    image_bytes = response.content
    mymodule.process_image(image_bytes)


    However, with the sequential approach above you will be spending a lot of time waiting for responses from the remote server. To make this faster, you can download and process multiple files at once using aysncio and aiohttp. There's a good introduction to downloading files this way in Paweł Miech's blog post Making 1 million requests with python-aiohttp. The code you need will look something like the example at the bottom of that blog post (the one with the semaphore).






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      If you download the file with Python, then you can just do the image processing operation after the file download operation finishes. An example using requests:



      import requests
      import mymodule # The module containing your custom image-processing function

      for img in ("foo.png", "bar.png", "baz.png"):
      response = requests.get("http://www.example.com/" + img)
      image_bytes = response.content
      mymodule.process_image(image_bytes)


      However, with the sequential approach above you will be spending a lot of time waiting for responses from the remote server. To make this faster, you can download and process multiple files at once using aysncio and aiohttp. There's a good introduction to downloading files this way in Paweł Miech's blog post Making 1 million requests with python-aiohttp. The code you need will look something like the example at the bottom of that blog post (the one with the semaphore).






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        If you download the file with Python, then you can just do the image processing operation after the file download operation finishes. An example using requests:



        import requests
        import mymodule # The module containing your custom image-processing function

        for img in ("foo.png", "bar.png", "baz.png"):
        response = requests.get("http://www.example.com/" + img)
        image_bytes = response.content
        mymodule.process_image(image_bytes)


        However, with the sequential approach above you will be spending a lot of time waiting for responses from the remote server. To make this faster, you can download and process multiple files at once using aysncio and aiohttp. There's a good introduction to downloading files this way in Paweł Miech's blog post Making 1 million requests with python-aiohttp. The code you need will look something like the example at the bottom of that blog post (the one with the semaphore).






        share|improve this answer














        If you download the file with Python, then you can just do the image processing operation after the file download operation finishes. An example using requests:



        import requests
        import mymodule # The module containing your custom image-processing function

        for img in ("foo.png", "bar.png", "baz.png"):
        response = requests.get("http://www.example.com/" + img)
        image_bytes = response.content
        mymodule.process_image(image_bytes)


        However, with the sequential approach above you will be spending a lot of time waiting for responses from the remote server. To make this faster, you can download and process multiple files at once using aysncio and aiohttp. There's a good introduction to downloading files this way in Paweł Miech's blog post Making 1 million requests with python-aiohttp. The code you need will look something like the example at the bottom of that blog post (the one with the semaphore).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 at 5:50

























        answered Nov 11 at 6:47









        Jack Taylor

        2,020621




        2,020621






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246062%2fhow-to-find-if-a-file-has-been-downloaded-completely-using-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python