Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## Version 1.0.3

- Changed web server to be non-blocking if timeout is set to 0.

## Version 1.0.2

- Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion pyfunnel/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
14 changes: 9 additions & 5 deletions pyfunnel/core.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def wait_until(somepredicate, timeout, period=0.1, *args, **kwargs):
must_end = time.time() + timeout
while time.time() < must_end:
if somepredicate(*args, **kwargs):
return True
return
time.sleep(period)
return False
return


def exit_test(logger, list_files=None):
Expand Down Expand Up @@ -456,9 +456,13 @@ def browse(self, *args, **kwargs):
else:
raise KeyboardInterrupt

print('Server will run for {} s (or until KeyboardInterrupt) at:\n'.format(timeout) + \
'http://localhost:{}/funnel'.format(self.server_port))
wait_until(exit_test, timeout, 0.1, self.logger, *args)
if timeout < 0.00001:
worker = threading.Thread(target=wait_until(exit_test, timeout, 0.1, self.logger, *args))
worker.start()
Comment on lines +459 to +461

@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()

else:
print('Server will run for {} s (or until KeyboardInterrupt) at:\n'.format(timeout) + \
'http://localhost:{}/funnel'.format(self.server_port))
wait_until(exit_test, timeout, 0.1, self.logger, *args)
except KeyboardInterrupt:
print('KeyboardInterrupt')
finally:
Expand Down
Loading