Declare a global variable only in a context (with)
<p>I don't know if it is possible, but i need to set a global object but only in a context (with)</p>

<p>for example, i have 2 part of code. the first is a worker object that read and write some files. 
but the worker don't actually know the real path of these files, so i have created a wrapper for redirect the open to the good filepath.</p>

<p>the probleme is that i create a wraper for every task ( with its own files) for the worker.
i can't pass the wrapper for every function during the work. 
the best way to permit the working function to open through the wrapper is to set it global, but i am working with thread and i can't actually set it global (mutliple task with mutiple wrapper can be set up at the same time)</p>

<p>what i want is to do some thing like this:</p>

<pre><code>with init_current_wrapper(task) as wrapper: #  do_some_magic_for_set_it_global(wrapper)

    do_some_jobs_for_this(task) # all process inside can access THIS wrapper
</code></pre>

<p>and inside the process under "do_some_jobs_for_this()" i could do</p>

<pre><code>wrapper = get_current_wrapper()
wrapper.open("fakefilename")
#blablabla
</code></pre>

<p>without thread , a simple OSWrapper.get_current() could do it,  but with thread,i can't know what is the "good" wrapper with the current context.</p>

<p>any idea ?</p>

<p>thanks</p>
