WSL2 (including with Windows 20H1 2004) is known to have issues with having the WSL clock get hours or days behind actual time after the computer is suspended.
This issue was not seen in WSL1, but upon upgrading to WSL2 has been almost immediately apparent to multiple people that reported this issue.
This causes errors with build systems (including GNU Make and Ninja) and SSL verification among others.
A workaround for this, when it occurs (have to keep doing workaround) is to synchronize the software clock to the onboard hardware clock from WSL Terminal:
hwclock -s
or if suitable from Windows Terminal:
wsl --shutdown
If that doesn’t work, try using NTP from WSL Terminal:
Sometimes cryptic errors occur if there was a syntax error in a .bib BibTeX bibliography file that doesn’t disappear even when the .bib syntax is corrected.
The fix for this is often to delete the auto-generated files:
This function recursively zips files in directories, storing only the relative path due to the use of the “arcname” parameter.
Otherwise, you get the path relative to the root of your filesystem, which is rarely useful.
importzipfilefrompathlibimport Path
defzip_dirs(path: Path, pattern: str) -> T.List[Path]:
"""
recursively .zip a directory
""" path = Path(path).expanduser().resolve()
dlist = [d for d in path.glob(pattern) if d.is_dir()]
iflen(dlist) == 0:
raiseFileNotFoundError(f"no directories to zip under {path} with {pattern}")
for d in dlist:
zip_name = d.with_suffix(".zip")
with zipfile.ZipFile(zip_name, mode="w", compression=zipfile.ZIP_LZMA) as z:
for root, _, files in os.walk(d):
for file in files:
fn = Path(root, file)
afn = fn.relative_to(path)
z.write(fn, arcname=afn)
print("write", zip_name)
Matlab plotting can be quite slow, as can Python Matplotlib plotting.
Sometimes, Matlab
parfor
can be used to
plot in parallel,
when all parfor restrictions are met.
However, parallel plotting in Matlab doesn’t always work, or may work on some operating systems but not others.
So use great caution if making a “parfor” plotting loop–it may not work for others.
Problems when trying to do relatively simple plots in parallel:
Warning: A worker aborted during execution of the parfor loop. The parfor loop will now run again
on the remaining workers.
Error using distcomp.remoteparfor/rebuildParforController (line 194)
All workers aborted during execution of the parfor loop.
Warning: worker(s) crashed while executing code in the current parallel pool. MATLAB may attempt
to run the code again on the remaining workers of the pool, unless an spmd block has run. View the
crash dump files to determine what caused the workers to crash.
When desired and permitted by the computer filesystem, it’s possible to change file ownership.
This may be necessary when a file was inadvertently created with root / admin ownership by mistake, and it’s necessary for a general user to edit or access the file.
Changing file ownership can have unexpected consequences, like removing the ability of others to access the file or run a program depending on the file.
Therefore, file ownership changes should be done only when necessary and with consideration for others who may depend on the file.
These examples assume the file “example.txt” is in the current directory and the user logged in should own the file.
These tasks are similarly done in other languages such as
Go
or
Julia.
As long as the user has filesystem permission, Python can easily change file ownership across operating systems.
The “python_history” file contains recent commands entered into the Python interpreter.
“python_history” files with incorrect permissions can cause a message on exiting Python like:
Error in atexit._run_exitfuncs:
PermissionError: [Errno 13] Permission denied
Find the owner of ~/.python_history
macOS / Linux: ls -l ~/.python_history
Windows / PowerShell: (get-acl ~/.python_history).owner
If it does not show the current username, that’s likely the problem.
git-filter-repo
is a Python program that is generally recommended over Git filter-branch and BFG Repo Cleaner.
Other users of your repo will get an “unrelated history” error so they will have to reset or reclone the repo.
PEP517 / PEP518 introduced pyproject.toml as a supplement and even replacement for setup.py.
Pyproject.toml has been adopted by major Python projects including PyTest.
Some computers, especially those using system Python may be configured without a user site-packages directory.
When pyproject.toml is present, systems without a Python user site-packages directory may fail on pip install -e . with errors including:
running develop
WARNING: The user site-packages directory is disabled.
error: can’t create or remove files in install directory
The fix below will work with or without pyproject.toml, installing just like usual:
pip install . → under user site-packages, a static copy of the package (any package code changes require package reinstall)
pip install -e . → Python-style link in user site-packages to this code directory (live development code)
Note: some systems require python3 -m pip instead of plain pip.
A general fix is to make setup.py contain
site.ENABLE_USER_SITE = True.
If the computer admin has locked down the user directory (very rare) this may still not work.
This installs this package, as well as any prerequisites specified and not already installed under the Python user directory
site.USER_SITE.
curl and Wget are popular web interface command line utilities that among their many features can resume interrupted or canceled downloads.
curl is a library with a command-line frontend, while Wget is a command line tool.
Daniel Stenberg’s curl has a permissive license that has perhaps led it to become very widespread, installed “from the factory” in operating systems from Windows, macOS, Linux to automobiles and many other embedded systems.
curl’s
man page
is perhaps best used by text search.
curl -O -C - https://mysite.example
-C -
--continue-at - continue a previous transfer, automatically determining byte offset.