Skip to content

"timebudget is confused" when multi-threading #15

@edsenabr

Description

@edsenabr

Hi,

I'm writing a script that spawns multiple threads to GET multiple pages in parallel, and when I run it I see several messages like this:

timebudget.py:73: UserWarning: timebudget is confused: timebudget.start(do_something) without end
  warnings.warn(f"timebudget is confused: timebudget.start({block_name}) without end")
timebudget.py:82: UserWarning: timebudget is confused: timebudget.end(do_something) without start
  warnings.warn(f"timebudget is confused: timebudget.end({block_name}) without start")

I've recreated the issue with a very simple script that sleeps on a separate thread:

from timebudget import timebudget
from queue import Queue
from threading import Thread
from time import sleep

timebudget.set_quiet()
timebudget.report_at_exit()

def process_queue():
    while True:
        do_something(queue.get())
        queue.task_done()

@timebudget
def do_something(i):
    sleep(1)

queue = Queue()
for i in range(2):
    queue.put(i)


for i in range(2):
    Thread(target=process_queue, daemon=True).start()
queue.join()

... am I doing anything wrong?

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