mitogen-hq / mitogen

Distributed self-replicating programs in Python
https://mitogen.networkgenomics.com/
BSD 3-Clause "New" or "Revised" License
2.34k stars 199 forks source link

Idea: Unify mitogen.is_master, mitogen.parent_ids, ... #91

Open moreati opened 6 years ago

moreati commented 6 years ago

Could the 4 variables in mitogen/__init__.py be unified into one? Would there be benefit? As noddy example/straw design

Example Interpretation
mitogen.lineage == (0,) I am master, my context_id is 0, I have no parents
mitogen.lineage == (4, 0) I'm not master, my context_id is 4, my parent is context 0 (the master)
mitogen.lineage == (42, 4, 0) I'm not master, my context_id is 42, my parent is context 4
def is_master(lineage): return lineage == (0,)
def context_id(lineage): return lineage[0]
def parent_id(lineage): return lineage[1] # or could check length and return None?
def parent_ids(lineage): return lineage[1:]
dw commented 6 years ago

Still thinking about it, but thanks, you just helped me notice a bug in unix.py .. connect() is broken if the listener is not the master, because parent_ids isn't fully reproduced to the client

moreati commented 6 years ago

To clarify a little. This is a) half baked b) a what-if. It is not a request, just me thinking out loud. Please feel free to close this issue at will.

dw commented 6 years ago

There is one addition to the suggested helpers, which is something like "mitogen.is_privileged(context_id)".

dw commented 6 years ago

(in lieu of a tidier way to do privilege checking from service.py services, CALL_FUNCTION, and any other places I'm already forgetting)

dw commented 5 years ago

On a related note, I want to move the mitogen.* globals either to Router, or to some new 'identity document' class. There is no reason why a single program couldn't have multiple independent trees running at the same time, and in some cases it may make lots of sense (completely 'airgapped' routing within the same program etc)