一个小型的纯python实用程序包。
decore的Python项目详细描述
一个小型的纯python实用程序包。
fromdecoreimportlazy_property@lazy_propertydefparamless_big_calc():sub_res=[big_func(const)forconstinarray_of_constants]returnsum(sub_res)
内容
2 Decorators
2.1 lazy_property
lazy_propertydecorator用于修饰计算某些常量值或属性的函数,这些常量值或属性只需要计算一次。对修饰函数的第一次调用将运行它并在返回之前保存该值(在内存中);随后的调用将在不触发计算的情况下获取该值。
对于没有参数的函数,可以将其看作functools.lru_cache(maxsize=1)。
fromdecoreimportlazy_property@lazy_propertydefparamless_big_calc():"""I take a lot of time!"""sub_res=[big_func(const)forconstinarray_of_constants]returnsum(sub_res)
2.2 threadsafe_generator
threadsafe_generatordecorator使生成器具有线程安全性。这意味着可以为多个线程提供对修饰生成器的引用,并且保证流中的每个项都将只生成(即返回)一个线程。
fromdecoreimportthreadsafe_generator@threadsafe_generatordefuser_documents(day):"""I yield some MongoDB documents!"""client=get_mongodb_client(some_params)dt_obj=translate_day_to_dt(day)user_document_cursor=client.some_mongodb_query(dt_obj,SOME_CONST)whileTrue:yielduser_document_cursor.__next__()
3 Contributing
软件包作者和当前维护者是shay palachy(shay.palachy@gmail.com);非常欢迎您向他寻求帮助。捐款是非常受欢迎的。
3.1 Installing for development
克隆:
git clone git@github.com:shaypal5/decore.git
以开发模式安装,测试依赖项:
cd pdpipe pip install -e ".[test]"
3.3 Adding documentation
这个项目是使用numpy docstring conventions来记录的,之所以选择它们,是因为它们可能是最广泛传播的约定,它们都得到了sphinx等常用工具的支持,并产生了人类可读的docstring(当然,在我个人看来)。在记录添加到此项目中的代码时,请遵循these conventions。
4 Credits
由shay palachy(shay.palachy@gmail.com)创建。