From 12b903f02e974421d2045a01a2effc0882991790 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 22 Aug 2021 07:47:06 +0200 Subject: [PATCH] disable PDF lock (unnecessary in ScoDoc 9) --- app/scodoc/sco_pdf.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index 574fb8399..bed6ff317 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -30,13 +30,17 @@ reportlab n'est pas réentrante: il ne faut qu'une seule opération PDF au même moment. Tout accès à ReportLab doit donc être précédé d'un PDFLOCK.acquire() et terminé par un PDFLOCK.release() + + En ScoDoc 9, ce n'est pas nécessaire car on est multiptocessus / monothread. """ import io -import time -import re import os -import unicodedata +import queue +import re +import threading +import time import traceback +import unicodedata import reportlab from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak @@ -63,7 +67,6 @@ from app.scodoc.sco_utils import ( from app.scodoc.notes_log import log from app.scodoc.sco_exceptions import ScoGenError import sco_version -import six PAGE_HEIGHT = defaultPageSize[1] PAGE_WIDTH = defaultPageSize[0] @@ -337,14 +340,14 @@ import threading, time, six.moves.queue, six.moves._thread class PDFLock(object): def __init__(self, timeout=15): - self.Q = six.moves.queue.Queue(1) + self.Q = queue.Queue(1) self.timeout = timeout self.current_thread = None self.nref = 0 def release(self): "Release lock. Raise Empty if not acquired first" - if self.current_thread == six.moves._thread.get_ident(): + if self.current_thread == threading.get_ident(): self.nref -= 1 if self.nref == 0: log("PDFLock: release from %s" % self.current_thread) @@ -356,16 +359,32 @@ class PDFLock(object): def acquire(self): "Acquire lock. Raise ScoGenError if can't lock after timeout." - if self.current_thread == six.moves._thread.get_ident(): + if self.current_thread == threading.get_ident(): self.nref += 1 return # deja lock pour ce thread try: self.Q.put(1, True, self.timeout) - except six.moves.queue.Full: + except queue.Full: raise ScoGenError(msg="Traitement PDF occupé: ré-essayez") - self.current_thread = six.moves._thread.get_ident() + self.current_thread = threading.get_ident() self.nref = 1 log("PDFLock: granted to %s" % self.current_thread) -PDFLOCK = PDFLock() +class FakeLock: + "Pour ScoDoc 9: pas de verrou" + + def __init__(self, timeout=15): + self.timeout = timeout + self.current_thread = threading.get_ident() + + def acquire(self): + assert threading.get_ident() == self.current_thread + pass + + def release(self): + assert threading.get_ident() == self.current_thread + pass + + +PDFLOCK = FakeLock()