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

  • Home
  • SEARCH
  • 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 8938833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:43:20+00:00 2026-06-15T10:43:20+00:00

I have a very simple script that monitors a file transfer progress, comparing its

  • 0

I have a very simple script that monitors a file transfer progress, comparing its actual size with the target then calculating its hash, comparing with the desired hash and firing up a few extra things when everything seems alright.

I’ve replaced the tool used for the file transfers (wget) with deluged, which has a neat api to integrate with.

Instead of comparing the file progress and compare the hashes, I only need to know now when deluged finished downloading the files. To achieve that, I was able to modify this script to my needs, but I’m stuck trying to wrap my head around twisted framework, that deluged makes use of.

To try getting over it, I grabbed one sample script from twisted deferred documentation, wrapped a class around it and attempted to use the same concept I’m using on this script I mentioned.

Now, I don’t know exactly what to do with the reactor object, since it’s basically a blocking loop that can’t be restarted.

This is my sample code I’m working with:

from twisted.internet import reactor, defer
import time

class DummyDataGetter:
    done = False
    result = 0
    def getDummyData(self, x):
        d = defer.Deferred()
        # simulate a delayed result by asking the reactor to fire the
        # Deferred in 2 seconds time with the result x * 3
        reactor.callLater(2, d.callback, x * 3)
        return d

    def assignResult(self, d):
        """
        Data handling function to be added as a callback: handles the
        data by printing the result
        """
        self.result = d
        self.done = True
        reactor.stop()

    def run(self):

        d = self.getDummyData(3)
        d.addCallback(self.assignResult)

        reactor.run()

getter = DummyDataGetter()
getter.run()
while not getter.done:
    time.sleep(0.5)
print getter.result
# then somewhere else I want to get dummy data again

getter = DummyDataGetter()
getter.run() #this throws an exception of type error.ReactorNotRestartable
while not getter.done:
    time.sleep(0.5)
print getter.result

My questions are:

  1. Should reactor be fired in another thread to prevent it blocking the code?

  2. If so, how would I add more callbacks to this reactor living in a separate thread? Simply by doing something similar to reactor.callLater(2, d.callback, x * 3), from my main thread?

  3. If not, what is the technique to overcome this problem of not being able to starting/stopping reactor twice or more on the same process?

  • 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-15T10:43:21+00:00Added an answer on June 15, 2026 at 10:43 am

    OK, easiest approach I found to this is to simply have a separate script called using subprocess.Popen, dump the statuses of the torrents and anything else needed into the stdout (serialized using JSON) and pipe that into the calling script.

    Way less traumatic than learning twisted, but of course far away from optimal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I have a simple script that i am testing with, but its acting very
i have a very simple script that reads out a txt file, puts the
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have a very simple Powershell v1.0 script to kill processes by name: $target
I have a very simple greasemonkey script that I want to call an already
I have a very simple perl script that moves files (don't ask why i
I have a very simple script that slides a message down from the top
I have a very simple script that should change links' id s but somehow
I have a very simple js script that works for hovers, but I want

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.