Giter Site home page Giter Site logo

Comments (4)

webknjaz avatar webknjaz commented on May 20, 2024

Could you post a more detailed reproducer and a traceback? Or maybe add a PR with a test case for this?

from cheroot.

kasium avatar kasium commented on May 20, 2024

Not very nice, but here is a simple example

from threading import Event, Thread
from flask import Flask
from cheroot.wsgi import Server
from cheroot.workers.threadpool import WorkerThread

app = Flask("sample")
server = Server(("localhost", 5001), app)
stop_done = Event()
in_start = Event()

original_start = WorkerThread
def start(*args, **kwargs):
    in_start.set()
    stop_done.wait()
    original_start(*args, **kwargs)
WorkerThread.start = start

def target():
    in_start.wait()
    server.stop()
    stop_done.set()

thread = Thread(target=target)
thread.start()
server.safe_start()
thread.join()

Stacktrace

Exception in thread Thread-1 (target):
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.11.0/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/root/.pyenv/versions/3.11.0/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/root/foo.py", line 21, in target
    server.stop()
  File "/root/venv/lib/python3.11/site-packages/cheroot/server.py", line 2094, in stop
    self.requests.stop(self.shutdown_timeout)
  File "/root/venv/lib/python3.11/site-packages/cheroot/workers/threadpool.py", line 292, in stop
    worker.join(remaining_time)
  File "/root/.pyenv/versions/3.11.0/lib/python3.11/threading.py", line 1107, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started

Instead of the monkeypatching, now image that exactly before WorkerThread.start is called a signal occurs. The signal handler in my case will then ask the server to stop. This leads to the original issuue

from cheroot.

webknjaz avatar webknjaz commented on May 20, 2024

I suppose this snipped could be further simplified with

- from flask import Flask
- app = Flask("sample")
- server = Server(("localhost", 5001), app)
+ server = Server(("localhost", 5001), lambda *_, **__: None)

right?

from cheroot.

kasium avatar kasium commented on May 20, 2024

yes, this also works

from cheroot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.