I want to create two (or more) threads and in each of them to execute a different external program, let's say aaa
and bbb
. These external programs need libraries located in different directories, let's say in /aaalib
and /bbblib
, so I have to set the environment variable LD_LIBRARY_PATH
before executing them. I want to avoid using shell, so solutions like execution LD_LIBRARY_PATH=/aaalib aaa
ain't good.
The question is: how do I set the os.environ['LD_LIBRARY_PATH']
in such a way that it will have different values in different threads?
PS. I tried the solution os.environ['...'] = threading.local()
described here, but it fails in following way:
In [1]: import os, threading
In [2]: os.environ['LD_LIBRARY_PATH'] = threading.local()
-----------------------
TypeError Traceback (most recent call last)
<ipython-input-2-a2c8ef0b901b> in <module>()
----> 1 os.environ['LD_LIBRARY_PATH'] = threading.local()
/usr/lib/python2.7/os.pyc in __setitem__(self, key, item)
471 self.data = environ
472 def __setitem__(self, key, item):
--> 473 putenv(key, item)
474 self.data[key] = item
475 def update(self, dict=None, **kwargs):
TypeError: must be string, not thread._local