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, ...
Get Mastering PyCharm now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.