Archives de l’auteur : davidhxxx

Thread-safety in Python

queue module – A synchronized queue class queue module overview It implements multi-producer, multi-consumer queues. It is useful when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics. The … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Logging with Python

Import import logging Basic configuration for the logging system logging.basicConfig() Practical for simple scripts to do one-shot configuration of the logging package. The default behaviour is to create a StreamHandler which writes to sys.stderr, set a formatter using the BASIC_FORMAT … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Reflection built-in functions and Inspect module in python

Reflection built-in functions Return the type of an object: def type(object) The return value is a type object and generally the same object as returned by object.__class__: Get the attribute value by its name from an object: getattr(x, ‘y’) is … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

date, time and datetime in Python

Module presentation Basic types Aware and Naive instances Create date, time and datetime Create a datetime from a timestamp Date formatting Date computation Date comparison date, time and datetime Modules datetime module : classes for manipulating dates and times. dateutil … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Traceback module in python

General It provides a standard interface to extract, format and print stack traces of Python programs. It mimics the behavior of the Python interpreter when it prints a stack trace. The module uses traceback objects (of type types.TracebackType), which are … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

faulthandler and sys hook in python

faulthandler module : Dump the Python traceback General Content: functions to dump Python tracebacks explicitly, on a fault, after a timeout, or on a user signal. Signals/Faults handled: SIGSEGV, SIGFPE, SIGABRT, SIGBUS, SIGILL Warning: The fault handler is called on … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

aws load balancer presentation

Use Elastic Load Balancing to distribute traffic across the instances in your Auto Scaling group Elastic Load Balancing types – Application Load Balancer – Network Load Balancer – Gateway Load Balancer – Classic Load Balancer Which usages? Application Load Balancer: … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask Rest json with Marshmallow

Models Person from dataclasses import dataclass from typing import List   from flask_example import db from models.Address import Address     @dataclass class Person(db.Model): id: int = db.Column(db.Integer, primary_key=True) firstname: str = db.Column(db.String) lastname = db.Column(db.String) addresses = db.relationship(’Address’, back_populates=’person’, … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask-SQLAlchemy

Set up flask with SQLAlchemy Integrates SQLAlchemy with Flask from flask import Flask from flask_sqlalchemy import SQLAlchemy   app: Flask = Flask(__name__) db: SQLAlchemy = SQLAlchemy() # The import of MySQLAlchemyConfiguration must be after the initialization of db (SQLAlchemy instance) … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Flask: common problems

Common SQLAlchemy/marshmallow problems Problem: Object initialization order issue. In python and still more to in flask, the order of import and instantiation of python files and classes matters. To make it consistent, we need to be very careful. We can … Continuer la lecture

Publié dans Non classé | Laisser un commentaire