Question on multiple Python users in one application

Chris Angelico rosuav at gmail.com
Thu Oct 6 21:22:10 EDT 2016


On Fri, Oct 7, 2016 at 11:03 AM, Loren Wilton <myspamacct at earthlink.net> wrote:
> I've read that Python supports 'threads', and I'd assumed (maybe
> incorrectly) that these were somewhat separate environments that could be
> operating concurrently (modulo the GC lock). I assume that data can be
> shared between the threads, and probably will share automatically if the
> name of the item (or the reference) matches. But I'd also assumed that I
> might be able to do something like start a thread and tell it that it is
> working in "module user_42" or some such, so that by default it's data would
> not be global.
>
> Assuming that I'm not completely off-base about using threads, I don't
> really understand how to create a thread or destroy it. I'm also not
> completely clear on how much useful data there is that is thread local, and
> how much in the way of Python objects goes in the gloabl heap.
>

Threads don't really have much to do with namespacing and data
sharing. The two are broadly orthogonal. Basically, threads in Python
exist so that one function call can be running code while another one
is blocked (eg on I/O). Other than that, they're just two "current
stack location" markers, but they use the same namespaces, the same
globals, etc.

ChrisA



More information about the Python-list mailing list