Traceback (most recent call last):
  File "C:\Python27\lib\multiprocessing\", line 262, in _feed
PicklingError: Can't pickle <type 'generator'>: attribute lookup __builtin__.gen
erator failed

#python tcp://*:8080
import sys
import time
import zmq

from multiprocessing import Queue
import threading

import json
from json import dumps, loads, JSONEncoder, JSONDecoder
import pickle
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput

class PythonObjectEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, (list, dict, str, unicode, int, float, bool, 
            return JSONEncoder.default(self, obj)
        return {'_python_object': pickle.dumps(obj)}

def as_python_object(dct):
    if '_python_object' in dct:
        return pickle.loads(str(dct['_python_object']))
    return dct

context = zmq.Context()
sock = context.socket(zmq.PUSH)

def getcombinations():
    for ii in range(1,2000):
        for jj in range(1,2000):
            for kk in range(1,2000):
                yield [ii,jj,kk]

class StreamArray(list):
    def __iter__(self):
        return getcombinations()

    # according to the comment below
    def __len__(self):
        return 1

def worker():
    while True:
        if q.qsize() < 1000:

q = Queue(maxsize=1000)
t = threading.Thread(target=worker, args = ())
t.daemon = True

while True:
    #sock.send(sys.argv[1] + ':' + time.ctime())
    combobject = getcombinations()
    #sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
    if q.qsize() > 0:
        item = q.get()
        #sock.send(json.dumps(combobject, cls=PythonObjectEncoder))

Reply via email to