Dennis Lee Bieber
3/7/2008 4:55:00 AM
On Thu, 06 Mar 2008 22:35:18 -0500, Sam <sambo@voidstar.com> declaimed
the following in comp.lang.python:
> >
> > So why not just make the thread an attribute of the class instead.
> >
> >
> Maybe that would be clearer. Starting to wonder if I could return thread
> name this way, then again, I think part reason for this aproach was the
> fact that once started it could finish/crash all on it's lonesome and
> it's instance could wait for garbage collection.
>
> >> self.socket = cs
> >> self.rhost_addr = remote_address
> >> print "client_socket_handler.__init__(): ", self.socket,
> >> self.rhost_addr
> >> # t1 = threading.Thread( None,self.socket_handler, None, (5,78) )
> >> # t1.start()
> >
> > Which is about what you were doing here, but should have used
> > self.t1 =...
> > self.t1.start()
> >
> Well this shouldn't realy be here just stuff I pasted over.
> Which brings me to a question how to start my thread internaly.
> Once I managed to call __init__() I should be able to call
> self.start() nicht var? or is it vahr?
>
If the end-user isn't supposed to even know there is a thread
running...
class whatever(object):
def __init__(self, *args): #fit whatever args you need
self._myThread = threading.Thread(target=self._something,
args=(what, ever))
self.otherStuff = ...
self._myThread.start()
def _something(w, e):
#the function that should run as the thread worker
.... the actual thread becomes just an attribute...
> Heh. Besides I don't think NL is permisible as line separator.
> the command is at the beginnign and I don't expect to support
> any multitude of tags.
I was thinking something that might have been embedded in the data
itself, once you get to that point.
Consider the results of:
>>> sample="""line 1\r\nline 2\r\nembedded\nline\r\nsomething\r\n"""
>>> sample.split()
['line', '1', 'line', '2', 'embedded', 'line', 'something']
>>> sample.split("\r\n")
['line 1', 'line 2', 'embedded\nline', 'something', '']
>>> sample.split("\r")
['line 1', '\nline 2', '\nembedded\nline', '\nsomething', '\n']
>>> sample.splitlines()
['line 1', 'line 2', 'embedded', 'line', 'something']
>>> sample="""line 1\rline 2\rembedded\nline\rsomething\r"""
>>> sample.splitlines()
['line 1', 'line 2', 'embedded', 'line', 'something']
>>>
Note that use "\r\n" as the split argument keeps embedded \n, but
doesn't need a subsequent strip to remove the \n left when using just
"\r" to split. [It does, however, give an empty element following the
concluding "\r\n" but so would "\r" followed by strip]
splitlines() handles \r\n, \n, and \r as line endings -- and no stray
empty ending! (however, \n\r /does/ create an empty element)
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/