Skip to Content
Mastering Python Design Patterns - Second Edition
book

Mastering Python Design Patterns - Second Edition

by Kamon Ayeva, Sakis Kasampalis
August 2018
Intermediate to advanced
248 pages
5h 51m
English
Packt Publishing
Content preview from Mastering Python Design Patterns - Second Edition

A second example, using a third-party module

There is actually a library, called retrying, that can be used for adding retry behavior to parts of an application. Let's use it for a similar implementation as the one in the first example.

First, make sure you install retrying using the pip install retrying command.

We need to start our code with the following imports:

import timeimport sysimport osfrom retrying import retry

We reuse the same function for creating a file. You could actually externalize it to a common functions module from where you would import it, if you want. For clarity, let's repeat it here:

def create_file(filename, after_delay=5):    time.sleep(after_delay)    with open(filename, 'w') as f:        f.write('A file creation test')
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python Design Patterns - Second Edition - Second Edition

Learning Python Design Patterns - Second Edition - Second Edition

Chetan Giridhar, Gennadiy Zlobin

Publisher Resources

ISBN: 9781788837484Supplemental Content