[ TAG 270 ][16.12.2021] -Erfolgreich -IAP-20210601-20210722

 Bei diesen Bericht geht es um die Überlegung welche Daten als Attribute an den Prozess übergeben werden sollen?

Als Referenz habe ich mir Dokumente vom [2022-01-02][22:54:27] genommen. Die Dokumente führten ein TEST - [02.01.2022][2250]. Es geht um die RPRCSL-Liste und den problematischen Status STATE-0.

Beim Durchlesen der RPRCSL-Struktur sind mir folgende Daten aufgefallen. Dabei dürfen [logger_00] und [alog] Daten nicht miteinander verwechselt werden.
  • logger_00
    • idnt
    • pth
    • str_idnt
    • prj_idnt
    • p11_spi
  • alog
    • idnt
    • pth
    • str_idnt
    • prj_idnt
    • p11_spi
Für diese Daten eignen sich die Methoden  RAWARRAY_DECODER(raw_array=None) und RAWARRAY_ENCODER(utf8_str=None) sehr gut.

Bei der Struktur STATE-0 sieht es ganz anders aus. Da können nicht alle Daten erfasst werden. Zum Beispiel die pid des ALOG-Prozesses ist zu diesen Ausführungszeitpunkt nicht vorhanden.
  • state_00
    • pid (nicht vorhanden!)
    • ppid
    • status
    • t0
    • t1
    • t2
Ich habe mich entschieden folgende Attribute den ALOG-Prozess zu übergeben.

  • LOGGER-0
    • lg0_idnt
    • lg0_pth
    • lg0_str_idnt
    • lg0_prj_idnt
    • lg0_p11_spi
  • ALOG
    • alg_idnt
    • alg_pth
    • alg_str_idnt
    • alg_prj_idnt
    • alg_p11_spi
  • STATE-0
    • st0_ppid
    • st0_t0
    • st0_t1
    • st0_t2

Eine Möglichkeit, die ich sehr gut finde besteht in der Verwendung von kwargs.

Quelle:
  • *args and **kwargs
    • [ https://book.pythontips.com/en/latest/args_and_kwargs.html ]
    • [ https://stackoverflow.com/questions/38908663/python-multiprocessing-how-to-pass-kwargs-to-function ]
Hier ist ein kleiner Entwurf für die [kwargs]-Anwendung.
import multiprocessing
from multiprocessing import Process
from multiprocessing.sharedctypes import Value, Array
from multiprocessing.sharedctypes import RawArray
from ctypes import c_uint8


from ALOG_20210722 import GLOBALS_20210720_1330
from ALOG_20210722 import RPRCSL_20211219_0030
from STRUCT import PRTKL_202112082120 as prtkl_202112082120
from ALOG_20210722 import RPRCSL_LOGGER_20210929 as rprcsl_log
import os
import sys

# ----------------------------------------------------------------------
# PROCESS_ALOG_20210726_0110.py
# IAP-20210601-20210722-1145 > ALOG_20210722 > PROCESS_ALOG_20210726_0110.py
# PROZESS-MODUL für Audiologs
# ----------------------------------------------------------------------


def RAWARRAY_DECODER(raw_array=None):
byte_array = []
for e in raw_array:
byte_array.append(e)
byte_str = bytes(byte_array).decode(encoding='utf8')
return byte_str


def RAWARRAY_ENCODER(utf8_str=None):
binarr = bytearray(utf8_str, 'utf8')
rawArray = RawArray(c_uint8, len(binarr))

i = 0
for e in binarr:
rawArray[i] = binarr[i]
i += 1

return rawArray


def ALOG(**kwargs):
print("")
print("ALOG-PROCESS")
for key, value in kwargs.items():
print(f"{key}:{value}")
print(f"")


def GENERATE_ARGS(alog_glb):
tst2 = "C:\\ädesd"
lg0_idnt = RAWARRAY_ENCODER(utf8_str="lg0_idnt")
lg0_pth = RAWARRAY_ENCODER(utf8_str="lg0_pth")
lg0_str_idnt = RAWARRAY_ENCODER(utf8_str="lg0_str_idnt")
lg0_prj_idnt = RAWARRAY_ENCODER(utf8_str="lg0_prj_idnt")
lg0_p11_spi = RAWARRAY_ENCODER(utf8_str="lg0_p11_spi")

args = (alog_glb.RPRCSL,
lg0_idnt,
lg0_pth,
lg0_str_idnt,
lg0_prj_idnt,
lg0_p11_spi)

return args

def GENERATE_KWARGS(alog_glb):
kwargs = {"a": 3,
"b": 2
}
return kwargs

def START_PROCESS(alog_glb):
print(f"START_PROCESS -> START_PROCESS(alog_glb) wird ausgeführt.")
tst_arg = GENERATE_ARGS(alog_glb)
print(f"tst_args: {tst_arg}")
kwargs = GENERATE_KWARGS(alog_glb=alog_glb)
p = Process(target=ALOG, kwargs=kwargs)
p.start()
pid = p.pid
ppid = multiprocessing.process.current_process().pid

p.join()
print(f"alog_glb.RPRCSL: {alog_glb.RPRCSL}")


def STOP_LAST_PROCESS(alog_glb):
print("STOP_LAST_PROCESS")




Stand-[20220116][1827]
import multiprocessing
from multiprocessing import Process
from multiprocessing.sharedctypes import Value, Array
from multiprocessing.sharedctypes import RawArray
from ctypes import c_uint8


from ALOG_20210722 import GLOBALS_20210720_1330
from ALOG_20210722 import RPRCSL_20211219_0030
from STRUCT import PRTKL_202112082120 as prtkl_202112082120
from ALOG_20210722 import RPRCSL_LOGGER_20210929 as rprcsl_log
import os
import sys

# ----------------------------------------------------------------------
# PROCESS_ALOG_20210726_0110.py
# IAP-20210601-20210722-1145 > ALOG_20210722 > PROCESS_ALOG_20210726_0110.py
# PROZESS-MODUL für Audiologs
# ----------------------------------------------------------------------


def ALOG(rprcsl, **kwargs):
print("")
print("ALOG-PROCESS")
print("TEST_20220109_1755")
print("Gebe die kwargs aus:")
tst = kwargs.items()
lst = {}
for key, value in kwargs.items():
print(f"{key}:{value}")
lst.update({key: value})
print(f"tst[lg0_idnt]: {tst}")
print("")
print(f"lst: {lst}")
print(f"lst[lg0_idnt]: {lst['lg0_idnt']}")
print("")
print(f"rprcsl: {rprcsl}")
print("")
print("")


def GENERATE_KWARGS(alog_glb):
kwargs = {'lg0_idnt': "value - lg0_idnt",
'lg0_pth': "value - lg0_pth",
'lg0_str_idnt': "value - lg0_str_idnt",
'lg0_prj_idnt': "value - lg0_prj_idnt",
'lg0_p11_spi': "value - lg0_p11_spi",
'alg_idnt': "value - alg_idnt",
'alg_pth': "value - alg_pth",
'alg_str_idnt': "value - alg_str_idnt",
'alg_prj_idnt': "value - alg_prj_idnt",
'alg_p11_spi': "value - alg_p11_spi",
'st0_ppid': "value - st0_ppid",
'st0_t0': 0.0,
'st0_t1': "value - st0_t1",
'st0_t2': 0
}
return kwargs


def START_PROCESS(alog_glb):
print(f"START_PROCESS -> START_PROCESS(alog_glb) wird ausgeführt.")
kwargs = GENERATE_KWARGS(alog_glb=alog_glb)
p = Process(target=ALOG, args=(alog_glb.RPRCSL,), kwargs=kwargs)
p.start()
pid = p.pid
ppid = multiprocessing.process.current_process().pid

p.join()
print(f"alog_glb.RPRCSL: {alog_glb.RPRCSL}")


def STOP_LAST_PROCESS(alog_glb):
print("STOP_LAST_PROCESS")




Das ist ein Test zu dem Thema [kwargs]
Unglaublich finde ich, dass die Übergabe von Attributen über die [kwargs]-Methode
sehr einfach ist. Ich kann dabei auf C-Variablen verzichten.

Die Verwaltung von Datentypen entfällt für mich vollständig.

Die ersten Versuche waren sehr vielversprechend. Um Ehrlich zu sein, zu gut um Wahr zu sein. In der nächsten Worksession werde ich die [kwargs] mit Daten füllen. Ich bin echt gespannt ob alles so funktioniert, wie ich es mir vorgestellt habe.

Quellen:
  • Dict update
    • [https://www.programiz.com/python-programming/methods/dictionary/update]
  • Process - args und kwargs
    • [https://stackoverflow.com/questions/38908663/python-multiprocessing-how-to-pass-kwargs-to-function]
  • UTF-8 Tabelle
    • [https://www.utf8-zeichentabelle.de/unicode-utf8-table.pl?utf8=bin]
  • Char to Int
    • [https://docs.python.org/3.1/library/functions.html#chr]
    • [https://docs.python.org/3.1/library/functions.html#ord]
    • [https://stackoverflow.com/questions/8600552/python-get-character-code-in-different-encoding]
    • [https://techtutorialsx.com/2018/02/04/python-converting-string-to-bytes-object/]
  • Bytes to Integer
    • [https://stackoverflow.com/questions/34009653/convert-bytes-to-int]
    • [https://www.delftstack.com/de/howto/python/python-int-to-binary/]
    • [https://www.delftstack.com/de/howto/python/how-to-convert-bytes-to-integers/]
    • [https://www.w3resource.com/python/python-bytes.php]
    • [https://www.programiz.com/python-programming/methods/built-in/bytes]
    • [https://stackoverflow.com/questions/21017698/converting-int-to-bytes-in-python-3]
    • [https://www.kite.com/python/answers/how-to-convert-an-int-to-bytes-in-python]
  • Ausgabenformatierung Bin, Hex, Dec, Oct
    • [https://docs.python.org/3/library/string.html#string-formatting]


Hochachtungsvoll
Artem Kraft




Kommentare

Beliebte Posts aus diesem Blog

[ TAG 38 ][29.05.2021] - Erfolgreich - Freelancer-Portale

[ TAG 747 ][07.04.2023] -Erfolgreich -BNKTRS -Google Code -Objekt und Methodenliste

[ TAG 52 ][12.06.2021] - Erfolgreich - IAP-20210601-20210609-2325