timebudget
timebudget copied to clipboard
"timebudget is confused" when multi-threading
trafficstars
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?
@leopd, could you please merge the pull request I've sent to solve this issue and publish a new version of the package ?