Skip to content

Instantly share code, notes, and snippets.

@bloodywing bloodywing/log.py
Last active Aug 29, 2015

Embed
What would you like to do?
<_read[server] (<socket._socketobject object at 0x1fca8a0> )>
<read[server] (<socket._socketobject object at 0x1fca8a0>, '\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17' )>
<error[server] (<class 'msgpack.exceptions.ExtraData'>, ExtraData(), [' File "/home/pierre/src/circuits/circuits/core/manager.py", line 555, in _dispatcher\n value = handler(*eargs, **ekwargs)\n', ' File "untitled0.py", line 55, in read\n data = msgpack.unpackb(data.strip())\n', ' File "_unpacker.pyx", line 123, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:123)\n'] handler=<bound method Server.read of <Server/server 27602:MainThread (queued=2) [R]>>, fevent=<read[server] (<socket._socketobject object at 0x1fca8a0>, '\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17' )>)>
ERROR <handler[*.read] (Server.read)> (<read[server] (<socket._socketobject object at 0x1fca8a0>, '\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x91\xdc\x00\x18\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17' )>) {<class 'msgpack.exceptions.ExtraData'>}: unpack(b) received extra data.
File "/home/pierre/src/circuits/circuits/core/manager.py", line 555, in _dispatcher
value = handler(*eargs, **ekwargs)
File "untitled0.py", line 55, in read
data = msgpack.unpackb(data.strip())
File "_unpacker.pyx", line 123, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:123)
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 3 08:29:16 2014
@author: pierre
"""
import argparse
from random import randint
import msgpack
import pickle
from circuits import handler, Component, Debugger, Timer, Event
from circuits.node import Node, remote
from circuits.net.events import connect, write
from circuits.net.sockets import TCPClient, TCPServer
class my_event(Event):
""" my event """
class Client(Component):
def ready(self, *args):
print("Client ready!")
def connected(self, host, port):
Timer(1, my_event(), persist=True).register(self)
@handler('my_event', channels='*')
def my_event(self):
data = []
data.append(range(0, 24))
#packed = pickle.dumps(data)
packed = msgpack.packb(data)
self.fire(write(packed))
self.fire(write(packed))
class Server(Component):
def init(self):
bind = ('localhost', 8001)
Node(bind).register(self)
def read(self, sock, data):
#data = pickle.loads(data.strip())
data = msgpack.unpackb(data.strip())
print(data)
# circuits classes done
def main():
argparser = argparse.ArgumentParser(description='This is a bloody script')
argparser.add_argument('-c', '--client', help='The Client', action='store_true')
argparser.add_argument('-s', '--server', help='The Server', action='store_true')
args = argparser.parse_args()
if args.client:
client = Client() + Debugger()
node = Node().register(client)
node.add('test', 'localhost', 8001)
client.run()
if args.server:
(Server() + Debugger()).run()
main()
@bloodywing

This comment has been minimized.

Copy link
Owner Author

bloodywing commented Mar 3, 2014

Line 44 and 45 is intended

python testscript.py -c
python testscript.py -s

@prologic

This comment has been minimized.

Copy link

prologic commented Mar 3, 2014

The only way to avoid the buffering occuring internally at lines 44/45 is to do something like:

    yield self.call(write(packed), 'client')
    yield self.call(write(packed), 'client')

If this doesn't work you could try:

    self.fire(write(packed), 'client')
    yield self.wait("_write")
    self.fire(write(packed), 'client')
    yield self.wait("_write")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.