Padre::TaskManager - Padre Background Task Scheduler
require Padre::Task::Foo; my $task = Padre::Task::Foo->new(some => 'data'); $task->schedule; # handed off to the task manager
Padre uses threads for asynchroneous background operations which may take so long that they would make the GUI unresponsive if run in the main (GUI) thread.
This class implements a pool of a configurable number of re-usable worker threads. Re-using threads is necessary as the overhead of spawning threads is high. Additional threads are spawned if many background tasks are scheduled for execution. When the load goes down, the number of extra threads is (slowly!) reduced down to the default.
The constructor returns a
Padre::TaskManager object. At the moment,
Padre::TaskManager is a singleton. An object is instantiated when the editor object is created.
Set the minimum and maximum number of worker threads to spawn. Default: 1 to 3
The first workers are spawned lazily: I.e. only when the first task is being scheduled.
TODO: This is disabled for now since we need Wx 0.89 for stable threading.
Disable for profiling runs. In the degraded, threadless mode, all tasks are run in the main thread. Default: 1 (use threads)
The number of milliseconds to wait before checking for dead worker threads. Default: 15000ms
Padre::Task instance (or rather an instance of a subclass), schedule that task for execution in a worker thread. If you call the
schedule method of the task object, it will proxy to this method for convenience.
Create more workers if necessary. Called by
reap which is called regularly by the reap timer, so users don't typically need to call this.
Check for worker threads that have exited and can be joined. If there are more worker threads than the normal number and they are idle, one worker thread (per
reap call) is stopped.
This method is called regularly by the reap timer (see the
reap_interval option to the constructor) and it's not typically called by users.
Shutdown all services with a HANGUP, then stop all worker threads. Called on editor shutdown.
Returns the queue of tasks to be processed as a Thread::Queue object. The tasks in the queue have been serialized for passing between threads, so this is mostly useful internally or for checking the number of outstanding jobs.
Returns the number of milliseconds between the regulary cleanup runs.
Returns whether running in degraded mode (no threads, false) or normal operation (threads, true).
Returns the number of tasks that are currently being executed.
Gracefully shutdown the services by instructing them to hangup themselves and return via the usual Task mechanism.
Returns a list of the worker threads.
This event handler is called when a background task has finished execution. It deserializes the background task object and calls its
finish method with the Padre main window object as first argument. (This is done because
finish most likely updates the GUI.)
This event handler is called when a background task is about to start execution. It simply increments the running task counter.
Called by the toolbar task-status button. Dumps the list of running tasks to the output panel.
What if the computer can't keep up with the queued jobs? This needs some consideration and probably, the schedule() call needs to block once the queue is "full". However, it's not clear how this can work if the Wx MainLoop isn't reached for processing finish events.
Polling services 'aliveness' in a useful way , something a Wx::Taskmanager might like to display. Ability to selectivly kill tasks/services
The base class of all "work units" is Padre::Task.
Copyright 2008-2009 The Padre development team as listed in Padre.pm.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.