This month Anaconda 2021.05 was released. For the first time it contains support for “64-bit AWS Graviton2 (ARM64) platform”. Why do you care? Let’s look first on very short description of what is ARM64.

ARM (Advanced RISC Machine, originally Acorn RISC Machine. RISC = Reduced Instruction Set Computer) is a compact and energy saving, not a high performance chipset. Therefore according chipsets are primarily being used in mobile and energy saving devices like smartphones, tablets, IoT…

x64 type are usually used in according higher performance devices like desktop PCs, higher performance notebooks or even in servers and other business class…

Description of high-level API module at AlexBerUtils project

ymlparsers and parser modules serves as Low-Level API for this module. Here is the story about ymlparsers and here is is the story about parser.

The source code you can found here. It is available as part of my AlexBerUtils s project.

You can install AlexBerUtils from PyPi:

python3 -m pip install -U alex-ber-utils

You should also install some optional dependencies, such as jinja2. The easiest way is to run:

python3 -m pip install alex-ber-utils[yml]

Note also that hiyapyco should be at least 0.4.16.

See here for more details explanation on how to install.

Code example

Put the following files to…

This is first part of mini-series of Explaining invokedynamic. This is the full list of all articles:

Introduction. Part I

Toy example. Part II

Bootstrap method . Part III

Number multiplication (almost) complete example. Part IV

Dynamical hashCode implementation. Part V

Java 9 String concatenation. Part VI

Lambda. Part VII

Records. Part VII

Final notes. Part IX

Introduction

Since Java 7 new bytecode instruction invokedynamic (or indy) was added.

It was added in JSR 292 in about 2011. It was originally designed for supporting Dynamically Typed Languages, as JSR name stated. So, it was ignored by waste majority of Java developers.

Introduction

It is not strickly required to read, theoretical part. The main result of it is provided here.

The last example illustrate how to implement mixin in Python.

Theoretically, not for any inheritance graph C³ Linearization Algorithm can be linearized. In practice, it is rarely happen, and if it did, Python will emit en Error. Another name of this algorithm is MRO — Method Resolution Order.

That’s right, the Diamond problem can be solved (practically). We can use inheritance where both object has the state, and this will not cause any problem. …

and other routine

What is generator in Python? Let’s look on what Wikipedia has to say:

Note: I’ve simplified code a bit.

Generators were added to Python in version 2.2 in 2001.[6] An example generator:

In Python, a generator can be thought of as an iterator that contains a frozen stack frame. Whenever next() is called on the iterator, Python resumes the frozen frame, which executes normally until the next yield statement is reached. The generator's frame is then frozen again, and the yielded value is returned to the caller.

https://en.wikipedia.org/wiki/Generator_(computer_programming)#Python

So, does generator is simply iterator? But what…

Description module at AlexBerUtils project

This is Thin adapter layer that redirects stdout/stderr (or any other stream-like object) to standard Python’s logger.

The source code you can found here. It is available as part of my AlexBerUtils s project.

You can install AlexBerUtils from PyPi:

python3 -m pip install -U alex-ber-utils

You can optionally install some dependencies, such as jinja2. The easiest way is to run:

python3 -m pip install alex-ber-utils[yml]

Note also that hiyapyco should be at least 0.4.16.

However, this is not strictly required.

See here for more details explanation on how to install.

High-Level Description

This modules is based upon https://github.com/fx-kirin/py-stdlogging/blob/master/stdlogging.py See also https://github.com/fx-kirin/py-stdlogging/pull/1

Useful functions for Selenium umbrella project.

I’ve started to use Selenium’s related products and how found that documentation is misleading, it doesn’t promote best practice. Moreover, many components has memory/resource leaks that are not fixed for years. So I’ve created a utility project that encapsulated my “fixes” to Selenium and promotes best practice.

I will list some of the capabilities of my library:

  • create/destroy BmpDaemon(aka browsermobproxy.Server).
  • create/destroy BmpProxy (aka browsermobproxy.Client).
  • create/destroy SeleniumWebDriver (for example selenium.webdriver.Chrome.webdriver). (Can be any supported browser).
  • Taking screenshots.
  • Preparing browser’s data-dir for usage.
  • Enabling browser to download files.
  • Capturing network in har format.
  • Waiting for page…

Suppose, that you have some multi-threaded/multi-process application where each thread/process creates some file (each thread/process create different file) and you want to join them to one file. Created file have some naming convention, for example output*.txt, and the resulting file should be output.txt.

Note: You can put, for example, thread/process name in place of asterisk to make than unique enough.

Now, in the main process/thread you want to create final file that will have content of all created files (they’re identified by file mask, such as output*.txt) to one final file (such asoutput.txt).

Note: If you’re expecting to have some…

It is very difficult if not impossible to pickle exceptions back to the parent process.

Simple ones work, but many others don’t.

For example, CalledProcessError is not pickable (my guess, this is because of stdout, stderr data-members).

This means, that if child process raise CalledProcessError that is not catched, it will propagate to the parent process, but the propagation will fail, apparently because of bug in Python itself. This cause pool.join() to halt forever — and thus memory leak! See https://stackoverflow.com/questions/15314189/python-multiprocessing-pool-hangs-at-join and https://bugs.python.org/issue9400

So, I have created GuardedWorkerException context-manager to mitigate this problem.

The source code you can found here

Without worrying about current working directory (Python).

What if you have some script or application that uses relative path and you want to invoke it from another directory. To get things more complicated. maybe your “external” code also use relative path, but relative to another directory. Here, I will describe the recipe how you can make all of these to work.

Suppose, that you wrote some script or application that is packaged and installed as YourApp (that is, it is installed into site-packages or venv). Something like this:

Code of app.py:

Note: Here I’m using init_app_conf module. You can read about it here.

Typically, at the…

alex_ber

Senior Software Engineer at Pursway

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store