Python in Practice: Create Better Programs Using Concurrency, Libraries, and Patterns by Summerfield Mark

Python in Practice: Create Better Programs Using Concurrency, Libraries, and Patterns by Summerfield Mark

Author:Summerfield, Mark [Summerfield, Mark]
Language: eng
Format: epub
Publisher: Pearson Education
Published: 2013-08-20T00:00:00+00:00


* * *

def get_jobs(source, target):

for name in os.listdir(source):

yield os.path.join(source, name), os.path.join(target, name)

* * *

This function performs the same service as the previous subsection’s add_jobs() function, only instead of adding jobs to a queue, it is a generator function that yields jobs on demand.

Click here to view code image

* * *

def wait_for(futures):

canceled = False

copied = scaled = 0

try:

for future in concurrent.futures.as_completed(futures):

err = future.exception()

if err is None:

result = future.result()

copied += result.copied

scaled += result.scaled

Qtrac.report("{} {}".format("copied" if result.copied else

"scaled", os.path.basename(result.name)))

elif isinstance(err, Image.Error):

Qtrac.report(str(err), True)

else:

raise err # Unanticipated

except KeyboardInterrupt:

Qtrac.report("canceling...")

canceled = True

for future in futures:

future.cancel()

return Summary(len(futures), copied, scaled, canceled)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.