Running Double Track Python 2.7 & 3.10

Support for Python 2.7 is to be discontinued. It's replacements, Python 3.0 and later, have significant differences, some of which can be unexpected. Some of these I'm listing here. The main difference, string handling, is straightforward and clearly documented, and won't be described here.

The "xrange()" function in p2.7 has been renamed to replace the "range()" function in p3. If similar functionality as with p2.7 "range" is required then it must be defined. E.G. "def _range(*p): return list(range(*p))" Threading is handled differently, There is a compatible library, _thread , but it has some differences. All integers in p3 are treated as long. Explicit long integers as in p2.7 do not exist in p3.

The ctypes library is handled differently in versions 3.10 and later.
The sequence:


where functions are defined in libc works for version 3.9 and earlier but fails with 3.10 .
Including the following beforehand fixes this:

  class fresult(ct.Structure):
    _fields_ = [("bytes", ct.POINTER(ct.c_ubyte))]

A similar bug is found when a c program routine returns a pointer:
  class result(ct.Structure):
    _fields_ = [("length", ct.c_int),("bytes", ct.POINTER(ct.c_ubyte))]
  ba=bytearray(result.bytes[:result.length]) # works for python versions 3.10 and earlier. # worked for python version 3.9 and earlier

Python3 does not use stdout. This causes problems when redirecting output to a file. E.G. " > file" produces out of sequence output when output is both from python and ctypes as a result of separate buffers for python and C. It is necessary to coerce the python and ctypes outputs to the same stream to get legible output.

Debian Release Bookworm seems to have bugs which make bluetooth fail or become unreliable. This could have some connection with Python3 versions greater than or equal to 3.10 .