Giter VIP home page Giter VIP logo

Comments (3)

Slater-Victoroff avatar Slater-Victoroff commented on May 16, 2024

Did more digging into this error. Seems that tomorrow breaks if any type-checking whatsoever is done on the resulting object. So passing the results into most any library function should break.

from tomorrow.

madisonmay avatar madisonmay commented on May 16, 2024

Super valid complaint. It's actually unrelated to the kind of class being used -- it's simply that calls to isinstance and type(obj) don't actually trigger a __getattr__ call.

You can fix this by doing literally anything to the result object before calling a function that checks the results type. I would recommend calling tomorrow._wait() explicitly in these circumstances. Simplified example below:

import base64
import json

from tomorrow import threads
import requests

def save_image_json(images, filename):
    with open(filename, 'a') as sink:
        for i, image in enumerate(images):
            results = return_image_json(image)
            results._wait()
            sink.write(results) 

@threads(4)
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'

if __name__ == "__main__":
    # koala images
    images = [
        'http://i.imgur.com/1p5nKyZ.jpg',
        'http://i.imgur.com/lDt3nJ8.jpg', 
        'http://i.imgur.com/hkUeCBT.jpg', 
        'http://i.imgur.com/ZglSElj.jpg'
    ]
    save_image_json(images, filename='koalas.json')

I'm going to look into forcing isinstance and type to trigger resolution of the future, but I'm not entirely certain this is possible. If that doesn't work I'll probably just end up updating the README to make sure people are aware of this edge case.

from tomorrow.

980202006 avatar 980202006 commented on May 16, 2024

if I have the error after run code,what I get is all the Tomorrow class. Is there any method to deal with it?

from tomorrow.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.