metaprogramming   4964

« earlier    

sample text MAX RETRIES DECORATOR
def retries(max_tries, delay=1, backoff=2, exceptions=(Exception,), hook=None):
"""Function decorator implementing retrying logic. The decorator will call the function up \
to max_tries times if it raises an exception.
"""
def dec(func):
def f2(*args, **kwargs):
mydelay = delay
tries = range(max_tries)
tries.reverse()
for tries_remaining in tries:
try:
return func(*args, **kwargs)
except exceptions as e:
if tries_remaining > 0:
if hook is not None:
# hook is any function we want to call
# when the original function fails
hook(tries_remaining, e, mydelay)
sleep(mydelay)
mydelay = mydelay * backoff
else:
raise
else:
break
return f2
return dec
python  decorator  metaprogramming  programming  book 
29 days ago by Spark
Metaprogramming in ES6: Symbols and why they're awesome
ES6 comes with a slew of new metaprogramming tools, which provide low level hooks into code mechanics. With these comes Symbols, here's a look…
es6  javascript  symbols  es2015  metaprogramming 
5 weeks ago by Glutnix

« earlier    

related tags

2015  alan_kay  article  ast  book  c++  c++0x  c++11  c++1x  c  clang  class  clos  cocoa  code  codegen  compile  compilers  compiletime  computer-scientist  concepts  cs  decorator  descriptors  designpatterns  devel  development  django  dotnet  dsl  elements  elixir  erlang  es-next  es2015  es6  exceptions  f#  floss  fold  food4thought  functional-programming  functional  generator  github  golang  haskell  homoiconicity  inheritance  inria  inspiration  instrumentation  interesting  interpreters  intro  java  javascript  jetbrains  lang:js  language  language_design  library  linq  lisp  logging  lua  macro  macros  metaclass  metaclasses  module  module_builder  mop  now  object  ocaml  oop  opensource  oriented  overhead  paper  paulgraham  people  personal  peterdimov  philip-walder  plt  plugin  plugins  ppx  processor  programming  programming_language  proxies  proxy  python  rails  reference  refinement  reflection  repository  requests  research  researcher  robin_milner  ruby  sboot  scala  scheme  semantics  source  stagging  stedolan  structure  swift  symbols  talk  tdc  templates  terra  to-watch  tools  tutorial  typescript  usecases  video  web  xml 

Copy this bookmark:



description:


tags: