Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: cgi "print statement" in multithreaded enviroment? (http://www.velocityreviews.com/forums/t344484-re-cgi-print-statement-in-multithreaded-enviroment.html)

vegetax 05-03-2005 02:25 AM

Re: cgi "print statement" in multithreaded enviroment?
 
vegetax wrote:

> Jeff Epler wrote:
>
>> You could write something like
>> class ThreadSpecificFile:
>> def set_stdout(f):
>> self.files[thread_id] = f
>> def write(data):
>> self.files[thread_id].write(data)
>> sys.stdout = ThreadSpecificFile()
>> where you'll have to fill out a few more things like thread_id,
>> __init__, and a way to clean up items from self.files when a thread
>> passes away.
>>
>> Jeff

>
> Thats what i was looking for,Thanks =)
>


So it would be something like this, right??


class ThreadSpecificFile:
def __init__(s):
self.files = []
def set_stdout(f,thread_id):
self.files[thread_id] = f
def clean_up(thread_id):
del self.files[thread_id]
def write(data):
self.files[thread.get_ident()].write(data)

sys.stdout = ThreadSpecificFile()



Scott David Daniels 05-03-2005 02:35 PM

Re: cgi "print statement" in multithreaded enviroment?
 
vegetax wrote:
> So it would be something like this, right??
>
> class ThreadSpecificFile:
> def __init__(s):
> self.files = []
> def set_stdout(f,thread_id):
> self.files[thread_id] = f
> def clean_up(thread_id):
> del self.files[thread_id]
> def write(data):
> self.files[thread.get_ident()].write(data)
>
> sys.stdout = ThreadSpecificFile()


import sys, thread

class ThreadSpecificFile:
def __init__(self, original):
self.files = dict()
self.original = original

def set_stdout(self, f):
self.files[thread.get_ident()] = f

def close(self):
try:
this = self.stops().close()
except KeyError:
pass

def stops(self):
return self.files.pop(thread.get_ident())

def write(self, data):
self.files.get(thread.get_ident(),
self.original).write(data)
except KeyError:
self

sys.stdout = ThreadSpecificFile(sys.stdout)


--Scott David Daniels
Scott.Daniels@Acm.Org


All times are GMT. The time now is 09:01 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.