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 9115573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:27:54+00:00 2026-06-17T04:27:54+00:00

I’m trying to make a Python library to use the Ubutu One API from

  • 0

I’m trying to make a Python library to use the Ubutu One API from Objective-C. Here is my source code:
https://github.com/JoseExposito/U1-Finder-Plugin/blob/master/U1FinderLib/U1FinderLib.py

I need to make many calls to the API, for this reason I need to have my reactor running once instead of run it and stop it, like in the example of the Ubuntu One documentation:
https://one.ubuntu.com/developer/files/store_files/syncdaemontool

Because it is not possible to run twice the reactor… And I need to execute reactor.run() in a thread because I can not block the application that uses that library!

It is possible to do that? I’m not able to run the reactor in a thread and call the Ubuntu One API synchronous.

EDIT:

I’m using this simple source code to test the idea:

#!/usr/bin/env python
import objc
import thread
import os
import time
from   twisted.internet import reactor, defer
from   ubuntuone.platform.tools import (SyncDaemonTool, is_already_running)
from   threading import Thread
NSObject = objc.lookUpClass('NSObject')

##
# Variable to get the result of the calls to the Sync Daemon.
# The result is a JSON string stored in returned_value[0].
returned_value = ['']

##
# Objective-C facade to the methods of the U1FinderLib.
class U1FinderLib(NSObject):

    def init(self):
        self = super(U1FinderLib, self).init()
        self.sync_daemon_tool = SyncDaemonTool(None)
        Thread(target=reactor.run, args=(False,)).start()
        return self

    @objc.typedSelector('@@:')
    def volumeList(self):
        print "Begin volumeList"
        reactor.callLater(0, run_command, "volume_list", [], self.sync_daemon_tool)
        print "End volumeList"
        return returned_value[0]

##
# Auxiliar functions to call to the sync daemon.
@defer.inlineCallbacks
def run_command(action, params, sync_daemon_tool):
    print "run_command"
    running = yield is_already_running()
    print "After is_already_running"
    try:
        if not running:
            returned_value[0] = '{ type:"error" reason:"Sync Daemon is not running" }'
        else:
            print "Before run_action"
            yield run_action(action, params, sync_daemon_tool)
            print "After run_action"
    except Exception, e:
        returned_value[0] = '{ type:"error" reason:"Exception: %s" }' % e

@defer.inlineCallbacks
def run_action(action, params, sync_daemon_tool):
    if action == "volume_list":
        d = sync_daemon_tool.get_folders()
        returned_value[0] = yield d.addCallback(lambda r: volume_list(r))

# Volume List
def volume_list(folders):
    volumes_json = '{ type:"volume_list" volumes: { \n\t{ volume:"' + os.path.expanduser('~/Ubuntu One') + '" subscribed:"YES" }'
    for folder in folders:
        volumes_json += ',\n\t{ volume:"' + folder['path'] + '" subscribed:"' + ('YES' if bool(folder['subscribed']) else 'NO') + '" }'
    volumes_json += '\n} }'
    return volumes_json

if __name__ == '__main__':
    py = U1FinderLib.alloc().init()
    print py.volumeList()
    print "EXIT"

And this is the output of the program:

Begin volumeList
End volumeList

EXIT

The problem is that the “run_command” function is never called

  • 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-17T04:27:55+00:00Added an answer on June 17, 2026 at 4:27 am

    Rather than running the reactor in a thread, you should use a reactor which integrates with the application you want to use it in.

    For example, perhaps you want to use the CoreFoundation reactor (since your application uses Obj-C and has “Finder” in the name).

    If you really can’t do that (for example, if Ubuntu One requires a different reactor – I don’t know if this is the case), then you probably can run that reactor in a thread. Most reactors do support this, although if Ubuntu One requires a particular reactor, that reactor may not support threaded usage.

    You didn’t actually explain what problem you have when trying to run the reactor in a thread, so I can’t help you understand why it that didn’t work. However, it should be easy to do so. Just:

    from twisted.internet import reactor
    from threading import Thread
    
    Thread(target=reactor.run, args=(False,)).start()
    

    Keep in mind that once you choose to run the reactor in a thread, you may only use Twisted APIs in that thread.

    If this doesn’t work, provide more details about how it doesn’t work in your question.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to render a haml file in a javascript response like so:

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.