Python get free network port
Python script to get a free network port: getfreeport.py.
Python script to get a free network port: getfreeport.py.
Making Matplotlib/Seaborn plots in parallel executing threads in Python is one area where one may need to increase ulimit for files. That is, increase the limit for the maximum number of open files. The default maximum number of open file limits are like 1024 for Linux and 2560 for macOS.
This can lead to problems with Matplotlib like:
Too many open files: ‘/usr/share/fonts/truetype/msttcorefonts/arial.ttf’
Platform independent ulimit -n increase “ulimit_nofile.py”
Instead of one-off or sudo-requiring system parameter setting techniques, consider platform-independent Python.
This does not use sudo.
It instead makes temporary setting changes where feasible or at most user-profile specific system changes.
This change will be only for this instance of Python; once Python terminates even the same terminal session will have the original ulimit again.
#!/usr/bin/env python
try:
import resource as res
except ImportError: #Windows
res = None
def raise_nofile(nofile_atleast=4096):
"""
sets nofile soft limit to at least 4096, useful for running matlplotlib/seaborn on
parallel executing plot generators vs. Ubuntu default ulimit -n 1024 or OS X El Captian 256
temporary setting extinguishing with Python session.
"""
if res is None:
return (None,)*2
# %% (0) what is current ulimit -n setting?
soft,ohard = res.getrlimit(res.RLIMIT_NOFILE)
hard = ohard
# %% (1) increase limit (soft and even hard) if needed
if soft<nofile_atleast:
soft = nofile_atleast
if hard<soft:
hard = soft
print('setting soft & hard ulimit -n {} {}'.format(soft,hard))
try:
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except (ValueError,res.error):
try:
hard = soft
print('trouble with max limit, retrying with soft,hard {},{}'.format(soft,hard))
res.setrlimit(res.RLIMIT_NOFILE,(soft,hard))
except Exception:
print('failed to set ulimit, giving up')
soft,hard = res.getrlimit(res.RLIMIT_NOFILE)
return soft,hard
if __name__ == '__main__':
from argparse import ArgumentParser
p = ArgumentParser()
p.add_argument('-n','--nofile',help='max number of open files',type=int,default=4096)
p = p.parse_args()
soft,hard = raise_nofile(p.nofile)
print('ulimit -n soft,hard: {},{}'.format(soft,hard))Pure Python lineClipping.py for Cohen-Sutherland line clipping code.
These commands assume the username you want to manipulate is joe.
Note that adding sudo privileges gives them full control over the PC to install anything including rootkits and malware.
adduser joe sudodeluser joe sudogetent group sudoIf the option to upgrade the Ubuntu version doesn’t show up, try force-upgrade Ubuntu version with
do-release-upgrade -dThe choices for high power license free operation (such as for harmonic radar transmitters) are typically between the 915MHz, 2.4 GHz or 5.8 GHz bands. Other bands are available in specific countries, for example 868 MHz is often available where 915 MHz is not available. I do not say that you can blast across the whole band without a careful legal review of the regulations, but this page is perhaps a better place to start a marketable product than buying a 10 kW Furino marine radar at 9.3 GHz, where it’s only license-free aboard a seagoing vessel. High power makes harmonic radar easier, and university research exemptions have led to lots of papers using marine radars, but realize such marine radar based systems may struggle mightily to legally come to market. There have been enforcement actions against those using marine radars for “good” purposes, even far from any body of water.
| Band (MHz) | EIRP (Watts) USA |
|---|---|
| 902 - 928 | 4 |
| 2400 - 2483.5 | 4 |
| 5725 - 5875 | 4 |
The passive radar tags will create a useful emission at the second harmonic of the radar frequency.
Free space loss, the major limiting factor in maximum standoff distance between tag and radar, increases ~ f2 ~ (1/lambda)2
We obtain this fact by inspection of the Friis free space loss equation:
path loss dB = 20 log10((4 π d f)/c)
Therefore, all else being equal (antenna gains, power, etc.) if 915 MHz is used as the radar transmit frequency instead of 5.8 GHz, we expect
20log10(5800/915) + 20log10(11600/1830)= 32
dB less loss on the two-way path. So assuming I can use bigger antennas (radar and tags) on 915MHz to keep the same gain as on 5.8 GHz, I can use a 1 Watt radar at 915 MHz as effectively as a 1600 Watt radar at 5.8 GHz, with regard to maximum range. This may seem fantastic, but one would probably select an antenna for 5.8 GHz with more gain than at 915MHz, making the EIRP higher without a gigantic transmitter.
This is a strictly back-of-envelope approach, there are numerous factors to consider before selecting a frequency range for you application–contact us to discuss further.
We generally think only about the radar transmitter EIRP for unbiased tags, as the typical license-free emission limit (in the United States) of 500 uV/m @ 3 m = -41.3 dBm is easily met by the harmonic radar tag, since unbiased tags have 20-30 dB loss. Additionally, for the United States, the FCC has determined that such tags (like RFID) are passive devices and the certification is on the radar. For the case of biased tags, the battery is separate from the RF (there is no RF interaction due to the battery, the battery just reduces losses of the diode) and a similar FCC argument holds.
Here is an incomplete listing of countries–note this doesn’t mean you can blast your radar across the whole band necessarily, you will need to examine the particulars for each country.
| Country | Frequency [MHz] | EIRP [Watts] |
|---|---|---|
| USA | 902 - 928 | 4 |
| Canada | 902 - 928 | 4 |
| Mexico | 902 - 928 | 4 |
| Japan | 916.7 - 923.5 | 0.5 (4W licensed) |
| China | 920.5 - 924.5 | 2 |
| Hong Kong | 920 - 925 | 4 |
| South Korea | 917 - 920.8 | 4 |
| Australia | 920 - 926 | 4 |
| New Zealand | 915 - 925 | |
| United Kingdom | 915 - 921 | 4 |
| South Africa | 915.1 - 921 | 4 |
and very many more not listed here.
With only 3 to 26 MHz bandwidth depending on the country, by
Δ R > c/(2B)
we expect 40 to 6 meters range resolution. Depending on the application, one can make a workable system from that.
Since it takes a very strong signal, typically -30 dBm or more from the radar into the tag to generate a useful return, we don’t usually find interference on the radar transmit frequency to be a large concern. On the radar receive frequency, at the second harmonic of the transmit frequency, interference could be a concern for unmodulated radars using the 915/1830 MHz pair, since 1830 MHz is in LTE band 3. One can select a radar modulation scheme such that uncorrelated transmissions such as LTE have a minimal impact. For other frequency pairings, consider the types of RF environments your end users will be in. Is is a large dock with high power X-band radars on the container ships? Is it in the vicinity of fixed microwave or satellite links?
Many times, we select what is convenient at hand for preliminary experiments, or follow on what a previous paper used. It can be easier to prototype at lower frequencies and longer range can be achieved, but ensure your application can support the required tag antenna size. Consider the regulations and interference environments of your target markets. Don’t expect more than 10’s of meters range with unbiased diode tags, unless you have some specific experiments or other evidence supporting.
Reinstalling VirtualBox may fix issues with a missing kernel driver wanting to install dkms and run “/sbin/vboxconfig”. This error usually happens when going between VirtualBox major or point releases. It can also happen when upgrading the Linux operating system.
Uninstall old Virtualbox by
apt remove virtualboxor
dpkg -r virtualboxThen reinstall new Virtualbox:
gdebi virtualbox*.debSVXlink can be used as a Linux Echolink SERVER (repeater, link). Qtel is a Linux Echolink client. Echolink for Windows program also works very well from WINE.
apt install svxlink-server qtelCreate “~/.svxlink/svxlink.conf” containing
[SimplexLogic]
CALLSIGN= #your callsign e.g. W1AW
[RepeaterLogic]
CALLSIGN= #your callsign e.g. W1AWModify “/etc/svxlink/svxlink.d/ModuleEcholink.conf”
CALLSIGN= #your Echolink system callsign e.g. W1AW-L or W1AW-R need the appropriate suffix
PASSWORD= # your Echolink system passwordRestart the server and try to connect from Qtel or other Echolink client.
Remote upgrading an operating system over SSH is a little risky, so it should only be considered when you accept the full risk of having to go physically to the PC and reinstall everything, possibly losing the files. You will need an open firewall for the backup temporary SSH server enabled by the Ubuntu upgrade (port 1022?); perhaps open all ports temporarily to the IP address of your local laptop from the remote PC.
The commands to be run on the remote PC are
screen
do-release-upgrade -dSometimes an Ubuntu in-place upgrade will error, failing to install packages like:
systemd-sysv
init
gvfs
At the end of the install, the Ubuntu upgrade installer said the install had failed, and it was going to revert with dpkg --configure -a.
That will typically also fail.
As a last resort, consider a recovery procedure as below.
This will keep the new Ubuntu version if it works.
Open a second Terminal, WITHOUT clicking close on that dialog:
apt install gvfs init systemd-sysvIn the same new Terminal:
reboot