Threads + Enviroment Variables

chris liechti cliechti at gmx.net
Sat Sep 29 20:07:38 EDT 2001


"Adonis Vargas" <deltapigz at telocity.com> wrote in
news:RZqt7.2134$gQ.1240221 at newsrump.sjc.telocity.net: 

> im having problems accessing enviroment variables from within a thread;
> the error im am getting is an 'undefined' error, but the variables i
> definded but in a module-level.
> i.e.
> 
> -- in module something.py --
> something = []
> 
> -- in script --
> from something import * # import the variable 'something' right?
> 
> def somefunction(somevalue):
>     return somevalue+=1

i'm getting a sytax error here. i guess you meant "return somevalue + 1"

> 
> def somethreadedfunction():
>     for i in range(10):
>         something = somefunction(0) # boom. an 'undefined' error???

this creates a local valiable. you would like to have a "global" statement 
somewhere.

have you tried to access the variable with the full name, including the 
module (something.something = xx)? i don't know what happens to the 
module's variable when you assign a new value to the imported one.

>         print something
> 
> Thread(target=somethreadedfunction).start()
> --
> 
> now this is not the real code im working on; since the code im working
> on is very complex i chose not to paste it; just provided the general
> idea of what i am trying to accomplish, therefore the code provided
> could not be correct. 
> 
> any help would be greately be appreciated.

i've tried the above with a global variable and it worked. maybe you have a 
typo in your original code?

you're also aware of threading related issues when multiple thread access 
the same data, like invalid values?
(speaking of Locks, Semaphores, Events from the treading module)


-- 
chris <cliechti at gmx.net>




More information about the Python-list mailing list