Ah, that probably means you want separate interpreters, then.

I hope not, unless I can get separate simultaneous interpreters out of one CPython.dll in one Windows process space. I'm guessing that I can't, but since I really don't know what I'm doing with Python yet, maybe I'm wrong there.

(for instance, the interactive
interpreter uses "_" in the builtins to store your last result, and if
you have multiple users sharing the builtins, they'd be trampling over
each other's underscores).

I'm very new to Python and I suspect I don't completely understand what you mean by 'builtins' in this instance. Does Python have a non-module-scope namespace that contains things like _ ? Could you give me a pointer to any docs on this?

If it does, do you have an opinion on how hard it might be to wrap it in some form of module (or "super module"?) scope?

But if you accept that this is a shared
environment, with the consequences thereof, you could have easy and
convenient sharing - and might even be able to have a tiny hack around
the interactive interpreter to make it use a different module name,
instead of __main__. So you could do something like this:

#### User "Fred" ####
   etc.

So they would be *visibly* sharing state. This might be acceptable to
you and your users. It would be pretty easy to code up (with the
possible exception of the interactive mode).

What you show in example is just about exactly what I want. Each user by default will have his own auto-generated (or maybe overridable by the user) namespace, so normally can work independently. But given that he can get the namespace handle for some other user (which might not be an interactive user, it might be a background process) then they can share data.

The worry I have is any implicitly global variables, like underscore, and whatever else may exist in this global namespace. I'd really want some way to wrap those and make them unique for each user. I'm guessing that may mean hacking the code for CPython. I'd rather not do that, unless people would like the code back so I don't have my own unique branch that would break on each new release. But if that is what is needed, it is certainly something I could do.

One concern I have is if two users both "import widget". Are they now sharing the widget namespace? I suspect they are, and that is probably undesirable. Or does Python have a hierarchical namespace concept, so that we would have fred.widget.ham and joe.widget.ham after fred and joe both import widget?

Thanks again!

Loren
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to