Code Monkey home page Code Monkey logo

Comments (7)

justvanrossum avatar justvanrossum commented on May 19, 2024

Hi Maarten, it sounds like perhaps two things:

  • Somehow you're not getting a fresh DB context when creating a new graphic
  • Perhaps Django is threaded, and (when reloading quickly) two threads access the same DB context

The solution for both could be the same.

Can you show me how you are calling drawbot-skia from your server app? Replace the actual drawing with a dummy rectangle to keep the example simple.

from drawbot-skia.

meyouwe avatar meyouwe commented on May 19, 2024

Hi Just. Thanks very much for getting back to me. The "not getting a fresh DB context" point you made is all I needed to fix the issue. Days of bouncing around heaps of different ideas and it was as simple as putting importlib.reload(db) in the top of function to reload the library each time.

import drawbot_skia.drawbot as db

def rect(request):
     importlib.reload(db)
     db.size(100, 100)
     db.fill(0, 1, 0)
     db.rect(0, 10, 50, 50)
     db.saveImage(f"media/rect.svg")
     return HttpResponse("<html><body>Done</body></html>")

Thank you again. Very grateful for your guidance.

from drawbot-skia.

justvanrossum avatar justvanrossum commented on May 19, 2024

Reload the module may be effective but is not a great solution. I'll try to post a better fix later.

from drawbot-skia.

meyouwe avatar meyouwe commented on May 19, 2024

Actually adding db.newDrawing() also works. Would that be a better solution?

from drawbot-skia.

justvanrossum avatar justvanrossum commented on May 19, 2024

Ah yes, newDrawing is a pretty essential thing indeed. Perhaps it's good enough, but try some stress-testing: if this code is indeed run from multiple threads, there will be hard-to-reproduce problems.

from drawbot-skia.

justvanrossum avatar justvanrossum commented on May 19, 2024

The following example should be thread-safe:

from drawbot_skia.drawing import Drawing
# from drawbot_skia.path import BezierPath
# from math import *
# from random import randint, random

db = Drawing()
db.rect(10, 10, 200, 300)
db.saveImage("maarten_test.png")

I added some comments to show where you'd find names that are normally part of the "drawbot" namespace, but aren't part of the Drawing class.

from drawbot-skia.

meyouwe avatar meyouwe commented on May 19, 2024

This is great Just. Thank you very much for the hand up.

from drawbot-skia.

Related Issues (17)

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.