Lambda returning tuple question, multi-expression
aapost
aapost at idontexist.club
Fri Mar 10 19:07:12 EST 2023
On 3/10/23 18:46, aapost wrote:
> main.pids.update({"messages" :subprocess.Popen(["tail", "-n",
> "1", "-f", "/var/log/messages"])}),
> main.pids.update({"syslog" :subprocess.Popen(["tail", "-n",
> "1", "-f", "/var/log/syslog"])}),
> main.pids.update({"kern" :subprocess.Popen(["tail", "-n", "1",
> "-f", "/var/log/kern.log"])}),
> main.pids.update({"user" :subprocess.Popen(["tail", "-n", "1",
> "-f", "/var/log/user.log"])}),
> ),
To pre-emptively address the bug there it would need to be:
main.pids.update({"messages" :subprocess.Popen(["tail", "-n", "1", "-f",
"/var/log/messages"])}) if not main.pids["messages"] else None,
main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", "1", "-f",
"/var/log/syslog"])}) if not main.pids["syslog"] else None,
main.pids.update({"kern" :subprocess.Popen(["tail", "-n", "1", "-f",
"/var/log/kern.log"])}) if not main.pids["kern"] else None,
main.pids.update({"user" :subprocess.Popen(["tail", "-n", "1", "-f",
"/var/log/user.log"])}) if not main.pids["user"] else None,
which does start to break down readability due to line length, as there
isn't really an indention rule set for something uncommonly used.
but some renaming makes the pattern clearer
pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not
pids["messages"] else None,
pids.update({"syslog" :subprocess.Popen(["cmd2"])}) if not
pids["syslog"] else None,
pids.update({"kern" :subprocess.Popen(["cmd3"])}) if not pids["kern"]
else None,
pids.update({"user" :subprocess.Popen(["cmd4"])}) if not pids["user"]
else None,
and adding a comment to say something like
# starting a series of processes via lambda tuple sequence if process
not running
#pattern: p.update({"name":sp.Popen(cmd)}) if not p["name"] else None,
More information about the Python-list
mailing list