1Padre::TaskManager(3) User Contributed Perl DocumentationPadre::TaskManager(3)
2
3
4
6 Padre::TaskManager - Padre Background Task Scheduler
7
9 require Padre::Task::Foo;
10 my $task = Padre::Task::Foo->new(some => 'data');
11 $task->schedule; # handed off to the task manager
12
14 Padre uses threads for asynchronous background operations which may
15 take so long that they would make the GUI unresponsive if run in the
16 main (GUI) thread.
17
18 This class implements a pool of a configurable number of re-usable
19 worker threads. Re-using threads is necessary as the overhead of
20 spawning threads is high. Additional threads are spawned if many
21 background tasks are scheduled for execution. When the load goes down,
22 the number of extra threads is (slowly!) reduced down to the default.
23
25 Class Methods
26 "new"
27
28 The constructor returns a "Padre::TaskManager" object. At the moment,
29 "Padre::TaskManager" is a singleton. An object is instantiated when
30 the editor object is created.
31
32 Optional parameters:
33
34 min_no_workers / max_no_workers
35 Set the minimum and maximum number of worker threads to spawn.
36 Default: 1 to 3
37
38 The first workers are spawned lazily: I.e. only when the first task
39 is being scheduled.
40
41 use_threads
42 Disable for profiling runs. In the degraded, thread-less mode, all
43 tasks are run in the main thread. Default: 1 (use threads)
44
45 reap_interval
46 The number of milliseconds to wait before checking for dead worker
47 threads. Default: 15000ms
48
49 Instance Methods
50 "schedule"
51
52 Given a "Padre::Task" instance (or rather an instance of a subclass),
53 schedule that task for execution in a worker thread. If you call the
54 "schedule" method of the task object, it will proxy to this method for
55 convenience.
56
57 "setup_workers"
58
59 Create more workers if necessary. Called by "reap" which is called
60 regularly by the reap timer, so users don't typically need to call
61 this.
62
63 "reap"
64
65 Check for worker threads that have exited and can be joined. If there
66 are more worker threads than the normal number and they are idle, one
67 worker thread (per "reap" call) is stopped.
68
69 This method is called regularly by the reap timer (see the
70 "reap_interval" option to the constructor) and it's not typically
71 called by users.
72
73 "cleanup"
74
75 Shutdown all services with a HANGUP, then stop all worker threads.
76 Called on editor shutdown.
77
78 Accessors
79 "task_queue"
80
81 Returns the queue of tasks to be processed as a Thread::Queue object.
82 The tasks in the queue have been serialized for passing between
83 threads, so this is mostly useful internally or for checking the number
84 of outstanding jobs.
85
86 "reap_interval"
87
88 Returns the number of milliseconds between the regular cleanup runs.
89
90 "use_threads"
91
92 Returns whether running in degraded mode (no threads, false) or normal
93 operation (threads, true).
94
95 "running_tasks"
96
97 Returns the number of tasks that are currently being executed.
98
99 "shutdown_services"
100
101 Gracefully shutdown the services by instructing them to hangup
102 themselves and return via the usual Task mechanism.
103
104 "workers"
105
106 Returns a list of the worker threads.
107
108 Event Handlers
109 "on_task_done_event"
110
111 This event handler is called when a background task has finished
112 execution. It deserializes the background task object and calls its
113 "finish" method with the Padre main window object as first argument.
114 (This is done because "finish" most likely updates the GUI.)
115
116 "on_task_start_event"
117
118 This event handler is called when a background task is about to start
119 execution. It simply increments the running task counter.
120
121 "on_service_poll_event"
122
123 "on_dump_running_tasks"
124
125 Called by the toolbar task-status button. Dumps the list of running
126 tasks to the output panel.
127
129 What if the computer can't keep up with the queued jobs? This needs
130 some consideration and probably, the "schedule()" call needs to block
131 once the queue is "full". However, it's not clear how this can work if
132 the Wx "MainLoop" isn't reached for processing finish events.
133
134 Polling services aliveness in a useful way, something a
135 "Wx::Taskmanager" might like to display. Ability to selectively kill
136 tasks/services
137
139 The base class of all "work units" is Padre::Task.
140
142 Steffen Mueller "smueller@cpan.org"
143
145 Copyright 2008-2010 The Padre development team as listed in Padre.pm.
146
147 This program is free software; you can redistribute it and/or modify it
148 under the same terms as Perl 5 itself.
149
150
151
152perl v5.12.1 2010-06-11 Padre::TaskManager(3)