Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:29:42+00:00 2026-05-27T13:29:42+00:00

Just for instance, this code is working import urllib image = urllib.URLopener() file_ =

  • 0

Just for instance, this code is working

import urllib

image = urllib.URLopener()
file_ = 1
name = 1
for i in range(1,1000):
    try:
        image.retrieve("http://mangawriter.com/pics/pic"+str(file_)+".jpeg","pic"+str(name)+".jpeg")
        print "save file %s" %file_ 
        name += 1
        file_ += 1
    except IOError:
        file_ += 1

How could I make it stop after some time was spent, even if the code is still being ran? Please, help me to figure it out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:29:43+00:00Added an answer on May 27, 2026 at 1:29 pm

    I would use the multiprocessing module, which generates new processes (not threads) for parallelizing tasks.

    How to do it? First, the actual download code should be put in a function:

    import urllib
    import multiprocessing
    import time
    
    def download_images():
        image = urllib.URLopener()
        file_ = 1
        name = 1
        for i in range(1,1000):
            try:
                image.retrieve("http://mangawriter.com/pics/pic"+str(file_)+".jpeg","pic"+str(name)+".jpeg")
                print "save file %s" %file_ 
                name += 1
                file_ += 1
            except IOError:
                file_ += 1
    

    Now, we create a new multiprocessing.Process object, passing the function above as its target. This object will start a process just to execute this function:

    downloader = multiprocessing.Process(target=download_images)
    

    Once we have created the process object, just call its start() method. This will start a process that will run in parallel:

    downloader.start()
    

    Since it is running in parallel, the main program keeps executing. Now, we define a timeout and sleep for the time of this timeout. In the example below, the timeout is 15 seconds:

    timeout = 15
    time.sleep(timeout)
    

    Once the timeout ends, just terminate the downloader process:

    downloader.terminate()
    

    The full program can be found here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

will this code when working show custom pins and logos or just 1 pin
This week I've been working on some reflection-based code, and during unit testing found
I am working in the .NET 2.0 framework. I have some code working, just
I just wondering how I could replace the second instance of a string inside
See code just bellow Our generic interface public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> { void add(INSTANCE_CLASS
I am trying to avoid hard-coding each instance of this WYSIWYG editor so I
This may seem obvious to most people, but I'm just trying to confirm that
I've spent half day trying to figure out this and finally I got working
So far, I have some working code that goes into a list of servers
I'm trying to run a Python script from a Cocoa app. It's working just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.