Format: application/x-python-code
1 o
2
3 ��hJE � @ s� d Z ddlZddlZddlmZ ddlmZ ddlmZm Z G dd� de
4 �ZG dd � d ej�Z
5 G d
6 d� de
7 �ZG dd
8 � d
9 e
10 �ZdS )a
11 Manage background (threaded) jobs conveniently from an interactive shell.
12
13 This module provides a BackgroundJobManager class. This is the main class
14 meant for public usage, it implements an object which can create and manage
15 new background jobs.
16
17 It also provides the actual job classes managed by these BackgroundJobManager
18 objects, see their docstrings below.
19
20
21 This system was inspired by discussions with B. Granger and the
22 BackgroundCommand class described in the book Python Scripting for
23 Computational Science, by H. P. Langtangen:
24
25 http://folk.uio.no/hpl/scripting
26
27 (although ultimately no code from this text was used, as IPython's system is a
28 separate implementation).
29
30 An example notebook is provided in our documentation illustrating interactive
31 use of the system.
32 � N)�get_ipython)�AutoFormattedTB)�error�debugc @ s� e Zd ZdZdd� Zedd� �Zedd� �Zedd � �Zd
33 d� Z dd
34 � Z
35 dd� Zdd� Zdd� Z
36 dd� Zdd� Zd&dd�Zdd� Zdd� Zdd � Zd!d"� Zd'd$d%�Zd#S )(�BackgroundJobManagera� Class to manage a pool of backgrounded threaded jobs.
37
38 Below, we assume that 'jobs' is a BackgroundJobManager instance.
39
40 Usage summary (see the method docstrings for details):
41
42 jobs.new(...) -> start a new job
43
44 jobs() or jobs.status() -> print status summary of all jobs
45
46 jobs[N] -> returns job number N.
47
48 foo = jobs[N].result -> assign to variable foo the result of job N
49
50 jobs[N].traceback() -> print the traceback of dead job N
51
52 jobs.remove(N) -> remove (finished) job N
53
54 jobs.flush() -> remove all finished jobs
55
56 As a convenience feature, BackgroundJobManager instances provide the
57 utility result and traceback methods which retrieve the corresponding
58 information from the jobs list:
59
60 jobs.result(N) <--> jobs[N].result
61 jobs.traceback(N) <--> jobs[N].traceback()
62
63 While this appears minor, it allows you to use tab completion
64 interactively on the job manager instance.
65 c C sN g | _ g | _g | _i | _g | _g | _tj| _tj | _
66 tj| _tj
67 | _d| _d S )Nr )�_running�
68 _completed�_dead�all�_comp_report�_dead_report�BackgroundJobBase�stat_created_cZ
69 _s_created�stat_running_c�
70 _s_running�stat_completed_c�_s_completed�stat_dead_c�_s_dead�_current_job_id��self� r �Pc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/lib/backgroundjobs.py�__init__I s
71 zBackgroundJobManager.__init__c C � | � � | jS �N)�_update_statusr r r r r �running[ � zBackgroundJobManager.runningc C r r )r r r r r r �dead` r zBackgroundJobManager.deadc C r r )r r r r r r � completede r zBackgroundJobManager.completedc O s� t |�r|�di �}t|g|�R i |��}n;t|t�rM|s*t�d�}|j|j}}nt |�dkr7|d }}nt |�dkrB|\}}nt
72 d��t|||�}ntd��|�dd�rZd |_
73 | j|_| jd7 _| j�|� || j|j<