Skip to content

Old-style classes interfere with returning strings #22

@Slater-Victoroff

Description

@Slater-Victoroff

I have no idea how to solve this one, but when trying to return strings from a function decorated with an @threads, rather than executing, it simply errors. Code below to reproduce:

def download_nm(delimiter, source, dump):
    images = [line.split(delimiter)[10] for line in open(source)][1:]  # avoid header row
    with open(dump, 'a') as sink:
        for i, image in enumerate(images):
            results = return_image_json(image)  # type(results) == <type 'instance'> 
            sink.write(results)  # Error, expected string or buffer

@threads(16)
def return_image_json(image_link):
    response = requests.get(image_link)
    encoded = "data:%s;base64,%s" % (response.headers['Content-Type'], base64.b64encode(response.content))
    return json.dumps({image_link: encoded}) + '\n'

It looks like moving to new-style classes resolves this issue, but since you're relying on some of the syntax-hacks of old-style classes I'm not sure if this is solvable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions