1. cherrypy
  2. CherryPy
  3. Pull requests

Pull requests

#20 Merged at ed118d1

Python3.3 doesn't use setdaemon for initializing the daemon var anymore

  1. Rene Peinthor

Python 3.3 changed the way how the daemon mode is initialized on threads. There is a now a constructor argument daemon that is used to set the mode and not anymore the setdaemon() function. I changed the BackgroundTask constructor to set the daemon mode more explicit. Without this patch in Python 3.3 the shutdown of cherrypy takes up to the frequency interval of the Monitor class to shutdown. Tested on Python 3.2 and 3.3

Comments (9)

  1. Jason R. Coombs

    Hi Rene. Thanks for the contrib. This does sound like something we want to fix. However, I believe your patch is not compatible with Python 2.3-2.7 (which CherryPy also supports). I suspect you may need to add some compatibility shim (see _cpcompat for all the hoops that CherryPy jumps through to maintain a single code base on Python 2+3) to restore the desired behavior.

  2. Rene Peinthor author

    Hi Jason!

    I updated the pull request, with changes for python 2. Tested on python 2.3 and 2.6.

    Btw. a decorator test has invalid syntax on python 2.3:

        byte-compiling /home/rp/py2.3/lib/python2.3/site-packages/cherrypy/test/_test_decorators.py to _test_decorators.pyc
        File "/home/rp/py2.3/lib/python2.3/site-packages/cherrypy/test/_test_decorators.py", line 9
        SyntaxError: invalid syntax
  3. Jason R. Coombs

    After further consideration, I don't see the value in adding to the constructor interface of BackgroundTask. Additionally, that 'daemon' parameter won't be honored on Python 2.5 or earlier (it will be set on the class, but not used by the superclass). Not to worry though. I appreciate the effort. I'll pull your changes and adapt them to something that achieves the same goals. Thanks again for bringing this to light.

  4. Rene Peinthor author

    For older python I think it will use the _set_daemon() function as before. At least that worked in my tests, and the new constructor argument is how python3 does it now.

  5. Jason R. Coombs

    SH**. I changed the pull request to pull into cherrypy-3.2.x, but bitbucket didn't do what I had expected (to cherrypick the pull request commits to that branch).

  6. Jason R. Coombs

    I've repaired the cherrypy-3.2.x branch (it no longer has recent ancestors in the default branch). I've also pushed an alternative approach that doesn't alter the BackgroundTask constructor interface, and should set the thread to daemonic on all supported Pythons.