Skip to content

Implemented non-blocking web server for #91 - #92

Closed
mwetter wants to merge 2 commits into
masterfrom
issue91_blockingWebServer
Closed

Implemented non-blocking web server for #91#92
mwetter wants to merge 2 commits into
masterfrom
issue91_blockingWebServer

Conversation

@mwetter

@mwetter mwetter commented Sep 15, 2025

Copy link
Copy Markdown
Member

This closes #91

This change is for lbl-srg/BuildingsPy#605

@AntoineGautier : While implementing it, I also saw #89 which is not yet merged and released. My testing does not include #89
Is #89 still needed? I am not sure if #89 actually solves the issue in lbl-srg/BuildingsPy#605 which is hard to reproduce as it only blocks sometimes, typically every 10th or 20th call to the web server.

We should decide if we should merge both, or only one of them, and then also make a funnel release so we can integrate it in BuildingsPy.

@AntoineGautier AntoineGautier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my inline comment.

You are correct, lbl-srg/BuildingsPy#605 may have different causes than the ones addressed with #89. Looking at the whole code, my take is that proc.terminate() at line 472 is most likely the culprit for blocking execution.

I think #89 is still needed though. It clearly solves plotting issues in many cases as mentioned in lbl-srg/BuildingsPy#600 (comment). However, there are some remaining "weird" cases occurring erratically. This is the reason why #89 is still being considered as work in progress.

Maybe improving the termination of the web browser with a timeout and a fallback kill command could resolve it all. Another option would be to replace HTTPServer with https://docs.python.org/3/library/http.server.html#http.server.ThreadingHTTPServer:

This is useful to handle web browsers pre-opening sockets, on which HTTPServer would wait indefinitely.

I could work on that over the next days if that helps.

Comment thread pyfunnel/core.py
Comment on lines +459 to +461
if timeout < 0.00001:
worker = threading.Thread(target=wait_until(exit_test, timeout, 0.1, self.logger, *args))
worker.start()

@AntoineGautier AntoineGautier Sep 17, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target argument of threading.Thread should be:

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

But here target is assigned the returned value of wait_until, which is None. So worker.start() below actually starts nothing (wait_until has already been called with zero timeout at the time worker is declared).

I think that the correct syntax should be:

worker = threading.Thread(target=wait_until, args=(exit_test, float('inf'), 0.1, self.logger) + args)
worker.daemon = True  # If the main program tries to exit, it won't wait for the `wait_until` monitoring thread

But even then, this doesn't seem to implement what's described in the issue:

to run the web server in a non-blocking thread if BuildingsPy requests a timeout=0

because the web server is launched separately with self.server_launch(), which already uses a non-blocking (daemon) thread:

    def server_launch(self):
        self.thread = threading.Thread(target=self.serve_forever)
        self.thread.daemon = True  # daemonic thread objects are terminated as soon as the main thread exits
        self.thread.start()

@AntoineGautier
AntoineGautier force-pushed the master branch 15 times, most recently from 2ca9e4d to 85ee936 Compare September 26, 2025 17:34
@AntoineGautier

Copy link
Copy Markdown
Collaborator

Most likely addressed with #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correct blocking web server when reference results changed

2 participants