O'Reilly logo

Mastering PyCharm by Quazi Nafiul Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with threads and processes

PyCharm has very good support for dealing with threads. Just like how we can change frames, we can also change threads if we so wish (that is, if we have more than one thread to begin with). Let's take the example of a simple downloader script called downloader.py:

# encoding=utf-8 from threading import Thread import requests def download(url): response = requests.get(url) if response.status_code == 200: print "Success -> {:<75} | Length -> {}".format(response.url, len(response.content)) else: print "Failure -> {:>75}".format(response.url) if __name__ == '__main__': urls = "http://www.google.com http://www.bing.com http://www.yahoo.com http://news.ycombinator.com".split() for u in urls: Thread(target=download, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required