Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:16:33+00:00 2026-06-01T07:16:33+00:00

I’m building an XML-RPC server using Twisted which periodically checks if the timestamps of

  • 0

I’m building an XML-RPC server using Twisted which periodically checks if the timestamps of its source files have changed and reloads them using rebuild.

from twisted.python.rebuild import rebuild

rebuild(mymodule)

The functions the server exposes get reloaded fine, but there in another protocol class active which calls callback functions on the same class of mymodule but they don’t use the reloaded version of the functions. This protocol simply has a dict with normal functions as values.

I found this mixin class which is intended to deal with limitations of rebuild.

http://twistedmatrix.com/documents/current/api/twisted.python.rebuild.Sensitive.html

How do I make sure my callbacks use up to date code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:16:34+00:00Added an answer on June 1, 2026 at 7:16 am

    You’re correct; this is a limitation of twisted.python.rebuild. It’s on updating the __class__ attribute of existing instances, and imported functions and classes.

    One way to deal with this would be to simply submit a patch to Twisted that fixes rebuild for this case.

    However, if you want to use Sensitive for its intended purpose, you can also implement your callback-holding class to work with rebuild on current versions of Twisted. The following examples demonstrates how to use all three methods of the relevant class to update a dictionary of callbacks pointing at functions. Note that even without the if needRebuildUpdate... test, calling x() directly will always get the most up-to-date version.

    from twisted.python.rebuild import rebuild, Sensitive
    from twisted.python.filepath import FilePath
    
    p = FilePath("mymodule.py")
    def clearcache():
        bytecode = p.sibling("mymodule.pyc")
        if bytecode.exists():
            bytecode.remove()
    clearcache()
    p.setContent("def x(): return 1")
    import mymodule
    from mymodule import x
    p.setContent("def x(): return 2")
    
    class Something(Sensitive, object):
        def __init__(self):
            self.stuff = {"something": x}
        def invoke(self):
            if self.needRebuildUpdate():
                for key in list(self.stuff):
                    self.stuff[key] = self.latestVersionOf(self.stuff[key])
                self.rebuildUpToDate()
            return self.stuff["something"]()
    
    def test():
        print s.invoke()
        print x()
    
    s = Something()
    test()
    
    clearcache()
    rebuild(mymodule)
    
    test()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.