• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript's Threadedness…
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript's Threadedness…


  • Subject: Re: AppleScript's Threadedness…
  • From: has <email@hidden>
  • Date: Wed, 19 Nov 2008 23:01:04 +0000

Simon Forster wrote:

I've got a main AppleScript script which can be called by any number of scripts - potentially simultaneously. In the main AppleScript I plan to have a lightweight run handler which will add the incoming request to a queue while other bits of the script may be tied up elsewhere. Will this work or is AppleScript strictly a one-task-at- a- time affair?

Use separate 'queue manager' and 'job runner' processes. Queue manager fires up a job runner as needed and passes it the info needed to process the job. When job runner completes, it sends a message to the queue manager to let it know. If you run jobs consecutively, you can do it all with standard AS applets; for concurrent job processing, it gets a bit more fiddly so ask if you need that.


Alternatively, use a language with threading support. e.g. My current project is a template-based artwork builder written in Python, using PyObjC and appscript. PyObjC provides the run loop and background thread, and appscript talks to Illustrator. Basically the same arrangement as above, except in a single process. The main thread provides the user interface for creating and configuring jobs and putting them into the job queue. The queue manager pops a job off the job queue and hands it off to the background thread to run without blocking the main thread. Once the job is complete, the background thread notifies the main thread and the cycle starts over again. (Alternatively I could've had the background thread pull jobs from the job queue independently of the main thread, but I'm lazy and doing it this way means I don't need to deal with additional synchronisation issues.) Works well. Fast too. :)

...

Christopher Nebel wrote:

It's currently not safe to use AppleScript anywhere other than the main thread.


Idle curiousity, but I've occasionally wondered if it'd be possible to use AS on a single background thread if you install your own send proc (to receive Apple events via a dedicated mach port). Or does the interpreter have other dependencies on the main thread as well?

Cheers,

has

--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: AppleScript's Threadedness…
      • From: Simon Forster <email@hidden>
    • Re: AppleScript's ThreadednessŠ
      • From: Emmanuel Levy <email@hidden>
  • Prev by Date: Re: AppleScript's ThreadednessŠ
  • Next by Date: Re: AppleScript's ThreadednessŠ
  • Previous by thread: Re: AppleScript's ThreadednessŠ
  • Next by thread: Re: AppleScript's ThreadednessŠ
  • Index(es):
    • Date
    • Thread