Question on multiple Python users in one application

Chris Angelico rosuav at gmail.com
Thu Oct 6 19:14:30 EDT 2016


On Fri, Oct 7, 2016 at 9:47 AM, Loren Wilton <myspamacct at earthlink.net> wrote:
> I don't think my main concern here is being able to call the CPython
> interpreter routines, but instead it is to be able to provide separate
> sandboxes for the various programs ("stacks", in B6500 terminology) that
> might have their own Python sessions or programs.
>
> One possible scenario is a B6500 user, sitting at a terminal, and typing
> "run python". That should get him a copyright notice and a >>> prompt, and
> he should be able to carry on just as though he was sitting at a Windows
> command line. The guy at the terminal in the next office should be able to
> be doing the same thing at the same time.

Ah, that probably means you want separate interpreters, then. My
previous idea of just having separate modules wouldn't isolate well
enough to feel properly comfortable (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). 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" ####
run python
Python 3.6, yada yada
Type "help" yada yada
>>> spam = 1234

#### User "Joe" ####
run python
Python 3.6, yada yada
Type "help" yada yada
>>> spam = 4321
>>> import fred
>>> print(fred.spam)
1234
>>> print(spam)
4321
>>> fred.ham = 2

#### User "Fred" ####
>>> print(spam)
1234
>>> print(ham)
2

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).

ChrisA



More information about the Python-list mailing list