KDE 4.5 PyKDE API Reference

- KDE's Python API

# Scheduler Class Reference

`from PyKDE4.kio import *`

Inherits: QObject
Namespace: KIO

## Detailed Description

The KIO.Scheduler manages io-slaves for the application. It also queues jobs and assigns the job to a slave when one becomes available.

There are 3 possible ways for a job to get a slave:

<h3>1. Direct</h3> This is the default. When you create a job the KIO.Scheduler will be notified and will find either an existing slave that is idle or it will create a new slave for the job.

Example:

        TransferJob *job = KIO.get(KUrl("http://www.kde.org"));

<h3>2. Scheduled</h3> If you create a lot of jobs, you might want not want to have a slave for each job. If you schedule a job, a maximum number of slaves will be created. When more jobs arrive, they will be queued. When a slave is finished with a job, it will be assigned a job from the queue.

Example:

        TransferJob *job = KIO.get(KUrl("http://www.kde.org"));
        KIO.Scheduler.scheduleJob(job);

<h3>3. Connection Oriented</h3> For some operations it is important that multiple jobs use the same connection. This can only be ensured if all these jobs use the same slave.

You can ask the scheduler to open a slave for connection oriented operations. You can then use the scheduler to assign jobs to this slave. The jobs will be queued and the slave will handle these jobs one after the other.

Example:

        Slave *slave = KIO.Scheduler.getConnectedSlave(
                KUrl("pop3://bastian:password@mail.kde.org"));
        TransferJob *job1 = KIO.get(
                KUrl("pop3://bastian:password@mail.kde.org/msg1"));
        KIO.Scheduler.assignJobToSlave(slave, job1);
        TransferJob *job2 = KIO.get(
                KUrl("pop3://bastian:password@mail.kde.org/msg2"));
        KIO.Scheduler.assignJobToSlave(slave, job2);
        TransferJob *job3 = KIO.get(
                KUrl("pop3://bastian:password@mail.kde.org/msg3"));
        KIO.Scheduler.assignJobToSlave(slave, job3);

        // ... Wait for jobs to finish...

        KIO.Scheduler.disconnectSlave(slave);

Note that you need to explicitly disconnect the slave when the connection goes down, so your error handler should contain:

        if (error == KIO.ERR_CONNECTION_BROKEN)
            KIO.Scheduler.disconnectSlave(slave);

See also:
  KIO.Slave

See also:
  KIO.Job

## Signals
| reparseSlaveConfiguration (QString a0)
| slaveConnected (KIO.Slave slave)
| slaveError (KIO.Slave slave, int error, QString errorMsg)
## Methods
| __init__ (self, KIO.Scheduler a0)
| __init__ (self)
bool | connect (self, QObject sender, QString signal, QString member)
## Static Methods
bool | assignJobToSlave (KIO.Slave slave, KIO.SimpleJob job)
| cancelJob (KIO.SimpleJob job)
| checkSlaveOnHold (bool b)
bool | connect (QString signal, QObject receiver, QString member)
bool | connect (QObject sender, QString signal, QObject receiver, QString member)
bool | disconnect (QObject sender, QString signal, QObject receiver, QString member)
bool | disconnectSlave (KIO.Slave slave)
| doJob (KIO.SimpleJob job)
| emitReparseSlaveConfiguration ()
KIO.Slave | getConnectedSlave (KUrl url, KIO.MetaData config=KIO.MetaData())
| jobFinished (KIO.SimpleJob job, KIO.Slave slave)
| publishSlaveOnHold ()
| putSlaveOnHold (KIO.SimpleJob job, KUrl url)
| registerWindow (QWidget wid)
| removeSlaveOnHold ()
| scheduleJob (KIO.SimpleJob job)
| setJobPriority (KIO.SimpleJob job, int priority)
| unregisterWindow (QObject wid)

## Signal Documentation

reparseSlaveConfiguration | ( | QString | a0
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("reparseSlaveConfiguration(const QString&)"), target_slot)`

slaveConnected | ( | KIO.Slave | slave
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("slaveConnected(KIO::Slave*)"), target_slot)`

slaveError | ( | KIO.Slave | slave,
|  | int | error,
|  | QString | errorMsg
| ) |  |  |

Signal syntax:
  `QObject.connect(source, SIGNAL("slaveError(KIO::Slave*, int, const QString&)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | KIO.Scheduler | a0
| ) |  |  |

__init__ | ( |  | self ) |

bool connect | ( | self, |
|  | QObject | sender,
|  | QString | signal,
|  | QString | member
| ) |  |  |

Function to connect signals emitted by the scheduler.

See also:
  slaveConnected()

See also:
  slaveError()

## Static Method Documentation

bool assignJobToSlave | ( | KIO.Slave | slave,
|  | KIO.SimpleJob | job
| ) |  |  |

Uses slave to do job. This function should be called immediately after creating a Job.

Parameters:

  | slave | The slave to use. The slave must have been obtained with a call to getConnectedSlave and must not be currently assigned to any other job.
  | job | The job to do.

Returns:
  true is successful, false otherwise.

See also:
  getConnectedSlave()

See also:
  disconnectSlave()

See also:
  slaveConnected()

See also:
  slaveError()

cancelJob | ( | KIO.SimpleJob | job
| ) |  |  |

Stop the execution of a job.

Parameters:

  | job | the job to cancel

checkSlaveOnHold | ( | bool | b
| ) |  |  |

When true, the next job will check whether KLauncher has a slave on hold that is suitable for the job.

Parameters:

  | b | true when KLauncher has a job on hold

bool connect | ( | QString | signal,
|  | QObject | receiver,
|  | QString | member
| ) |  |  |

Function to connect signals emitted by the scheduler.

See also:
  slaveConnected()

See also:
  slaveError()

bool connect | ( | QObject | sender,
|  | QString | signal,
|  | QObject | receiver,
|  | QString | member
| ) |  |  |

Function to connect signals emitted by the scheduler.

See also:
  slaveConnected()

See also:
  slaveError()

bool disconnect | ( | QObject | sender,
|  | QString | signal,
|  | QObject | receiver,
|  | QString | member
| ) |  |  |

bool disconnectSlave | ( | KIO.Slave | slave
| ) |  |  |

Disconnects slave.

Parameters:

  | slave | The slave to disconnect. The slave must have been obtained with a call to getConnectedSlave and must not be assigned to any job.

Returns:
  true is successful, false otherwise.

See also:
  getConnectedSlave

See also:
  assignJobToSlave

doJob | ( | KIO.SimpleJob | job
| ) |  |  |

Register job with the scheduler. The default is to create a new slave for the job if no slave is available. This can be changed by calling scheduleJob.

Parameters:

  | job | the job to register

emitReparseSlaveConfiguration | ( |  | ) |

KIO.Slave getConnectedSlave | ( | KUrl | url,
|  | KIO.MetaData | config=KIO.MetaData()
| ) |  |  |

Requests a slave for use in connection-oriented mode.

Parameters:

  | url | This defines the username,password,host & port to connect with.
  | config | Configuration data for the slave.

Returns:
  A pointer to a connected slave or 0 if an error occurred.

See also:
  assignJobToSlave()

See also:
  disconnectSlave()

jobFinished | ( | KIO.SimpleJob | job,
|  | KIO.Slave | slave
| ) |  |  |

Called when a job is done.

Parameters:

  | job | the finished job
  | slave | the slave that executed the job

publishSlaveOnHold | ( |  | ) |

Send the slave that was put on hold back to KLauncher. This allows another process to take over the slave and resume the job that was started.

putSlaveOnHold | ( | KIO.SimpleJob | job,
|  | KUrl | url
| ) |  |  |

Puts a slave on notice. A next job may reuse this slave if it requests the same URL.

A job can be put on hold after it has emit'ed its mimetype. Based on the mimetype, the program can give control to another component in the same process which can then resume the job by simply asking for the same URL again.

Parameters:

  | job | the job that should be stopped
  | url | the URL that is handled by the url

registerWindow | ( | QWidget | wid
| ) |  |  |

Register the mainwindow wid with the KIO subsystem Do not call this, it is called automatically from void KIO.Job.setWindow(QWidget*).

Parameters:

  | wid | the window to register

removeSlaveOnHold | ( |  | ) |

Removes any slave that might have been put on hold. If a slave was put on hold it will be killed.

scheduleJob | ( | KIO.SimpleJob | job
| ) |  |  |

Schedules job scheduled for later execution. This just sets the job's priority to 1 now.

Parameters:

  | job | the job to schedule

setJobPriority | ( | KIO.SimpleJob | job,
|  | int | priority
| ) |  |  |

Changes the priority of job; jobs of the same priority run in the order in which they were created. Jobs of lower numeric priority always run before any waiting jobs of higher numeric priority. The range of priority is -10 to 10, the default priority of jobs is 0.

Parameters:

  | job | the job to change
  | priority | new priority of job, lower runs earlier

unregisterWindow | ( | QObject | wid
| ) |  |  |

Internal:
  Unregisters the window registered by registerWindow().