twisted python separation of data between protocols -


A new protocol is created each time the connection is created, but I can create two types of data sharing between two types Seeing.

In short I have defined a class that will use for each protocol state JSONCollector (): char_buffer = StringIO.StringIO () ... def Process_data (self), data): ... self.char_buffer.write (char)

Protocol it immediately

  class JSONProtocol (protocol.Protocol) : Def __init__ (self): self.json_collector = JSONCollector () def data received (self, data): self.json_collector.process_data (data) self.transport.write (str (self))   

However each connection seems to get the same example of the JSONCollector Land, when I added the following statements to obtain the data. Self.transport.write (str (self.json_collector.char_buffer)) self.transport.write (str (self))

I get the following:

Connection 1: 0x 968ae2c String IO.StringIO Example & gt; 0x969036c & gt;

Connection 2: string IO.StringIO example at 0x968ae2c & lt; Chief . JSN Protocol Example & gt; 0x969068c

Every time I type in text, text written from other text (connections) is displayed. So it seems that some strange reason StringIO () examples are shared, am I forgetting something I think I can use a factory to separate buffer by Adrar and make sure that Each protocol uses its buffer only, but without the need to store the storage I will not run through hoops

thanks. P>

this:

  class JSONCollector (): char_buffer = StringIO.StringIO)   

Looks like an error, and instead of your source of troubles, try it:

  class JSONCollector (): def __init __ (auto ): Self.char_buffer = StringIO.StringIO ()   

Otherwise, unlike a copy example, creating a char_buffer for the whole class type

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -