#20 Merged
Repository
rp rp
Branch
default
Repository
cherrypy cherrypy
Branch
cherrypy-3.2.x

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

Author
  1. Rene Peinthor avatarRene Peinthor
Reviewers
Description

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
        @expose
        ^
        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.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.