[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] Remove all jobs run by a user / owner via python script.



On 1/3/2023 9:22 PM, gagan tiwari wrote:
Hi Vikrant / Jason,
                                Thanks for your email. 

I have been able to achieve it by using getpass.getuser().  

 schedd = htcondor.Schedd()
                schedd.act(htcondor.JobAction.Remove, f'Owner == "{getpass.getuser()}"')

Using the above codes , all jobs are removed owned by the user as returned by the getpass.getuser() function. 

However , still nothing gets printed to stdout.  


Hi Gagan,

The Schedd.act method does not print anything to stdout, it returns a ClassAd object.
In the below examples from Jason/Vikrant, they are using interactive Python command-line interpreter which, by default, prints to stdout the return value of any method invoked.  Note the below examples have the ">>> " prompt before every line - this is the giveaway that the Python interpreter is being used.

If you are using this code inside a python script, you should capture the return value to a variable, and then inspect and/or explicitly invoke the print() method to output to stdout.

This article may be of help:

  https://stackabuse.com/python-programming-in-interactive-vs-script-mode/

Hope this helps,
Todd







 





On Tue, Jan 3, 2023 at 8:26 PM Jason Patton via HTCondor-users <htcondor-users@xxxxxxxxxxx> wrote:
Hi Gagan,

As Vikrant showed, the Schedd.act method returns a ClassAd object containing the results of the action. It does not raise an error if nothing happened (unless there was a communication error with the schedd or something along those lines). Your code has to interpret the resulting ClassAd:

>>> import htcondor
>>> htcondor.version()
'$CondorVersion: 10.1.1 2022-11-11 BuildID: UW_Python_Wheel_Build RC $'
>>> schedd = htcondor.Schedd()
>>> schedd.act(htcondor.JobAction.Remove, 'Owner=="me"')
[ TotalChangedAds = 0; TotalJobAds = 29454; TotalPermissionDenied = 0; TotalAlreadyDone = 0; TotalBadStatus = 0; TotalNotFound = 0; TotalSuccess = 0; TotalError = 0 ]
>>> result = schedd.act(htcondor.JobAction.Remove, 'Owner=="me"')
>>> print(f"Jobs successfully removed: {result['TotalSuccess']}")
Jobs successfully removed: 0

If you want an error raised if nothing changed, you will have to code that based on the result that comes out of your schedd.act call.

Jason

On Tue, Jan 3, 2023 at 1:37 AM gagan tiwari <gagan.tiwari@xxxxxxxxxxxxxxxxxx> wrote:
Thanks Vikrant for your reply.   I will do as you suggested. 

 Mine   version of htcondor python. 

>>> import htcondor
>>> htcondor.version()
'$CondorVersion: 10.1.1 2022-11-11 BuildID: UW_Python_Wheel_Build RC $'
>>>

Thanks,
Gagan

On Tue, Jan 3, 2023 at 11:51 AM Vikrant Aggarwal <ervikrant06@xxxxxxxxx> wrote:
My suggestion would be to check whether you are able to query the jobs (if rm still not working for you) using python code. Also when you remove the job you should see something coming on stdout. I usually prefer to do this kind of debugging on the python terminal. 

regarding the version of htcondor python. 

>>> import htcondor
>>> htcondor.version()
'$CondorVersion: 8.9.11 Mar 17 2021 $'


Thanks & Regards,
Vikrant Aggarwal

On Mon, Jan 2, 2023 at 11:06 PM gagan tiwari <gagan.tiwari@xxxxxxxxxxxxxxxxxx> wrote:
Please update what I am missing.

Thanks,
Gagan

On Mon, Jan 2, 2023 at 10:39 PM gagan tiwari <gagan.tiwari@xxxxxxxxxxxxxxxxxx> wrote:
Not working for me.  Using following codes

def remove_jobs():

        user = "shrey"
        try:
               
                schedd = htcondor.Schedd()
                schedd.act(htcondor.JobAction.Remove, f'Owner == "{user}"')

         except Exception as e:
                print("An execption was thrown")
                print(e)

It just doesn't print anything. No output. 

How can I check htcondor python binding ?

Thanks,
Gagan



On Mon, Jan 2, 2023 at 10:14 PM Vikrant Aggarwal <ervikrant06@xxxxxxxxx> wrote:
Hello,

It seems to be working fine for me. I had htcondor python binding 8.9.11 for quick check.

>>> import htcondor
>>> schedd = htcondor.Schedd()
>>> user = "testuser1"
>>> schedd.act(htcondor.JobAction.Remove, f'Owner == "{user}"')
[ TotalJobAds = 1; TotalPermissionDenied = 0; TotalAlreadyDone = 0; TotalNotFound = 0; TotalSuccess = 1; TotalChangedAds = 1; TotalBadStatus = 0; TotalError = 0 ]
>>>

also if no job is present in the queue : it's not an error condition. 

>>> schedd.act(htcondor.JobAction.Remove, f'Owner == "{user}"')
[ TotalJobAds = 0; TotalPermissionDenied = 0; TotalAlreadyDone = 0; TotalNotFound = 0; TotalSuccess = 0; TotalChangedAds = 0; TotalBadStatus = 0; TotalError = 0 ]

If you don't have permission to remove other user jobs.

>>> schedd.act(htcondor.JobAction.Remove, f'Owner == "{user}"')
[ TotalJobAds = 40; TotalPermissionDenied = 40; TotalAlreadyDone = 0; TotalNotFound = 0; TotalSuccess = 0; TotalChangedAds = 0; TotalBadStatus = 0; TotalError = 0 ]

I suspect it could be related to permissioning? 



Thanks & Regards,
Vikrant Aggarwal


On Mon, Jan 2, 2023 at 9:36 PM gagan tiwari <gagan.tiwari@xxxxxxxxxxxxxxxxxx> wrote:
Hi Guys,
                 I need to allow users to remove all or few jobs submitted by them using a python script. 

I am using following codes :- 

def remove_jobs(user):
         schedd = htcondor.Schedd()
         schedd.act(htcondor.JobAction.Remove, f'Owner == "{user}"')

But the above codes seem to be not working as expected.

Even if NO job is run by the user above code doesn't throw an exception which means its not working correctly.

Someone please help how can I achieve this?

Thanks,
Gagan

_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/
_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/
_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/
_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/
_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/
_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/

_______________________________________________
HTCondor-users mailing list
To unsubscribe, send a message to htcondor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/htcondor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/htcondor-users/


-- 
Todd Tannenbaum <tannenba@xxxxxxxxxxx>  University of Wisconsin-Madison
Center for High Throughput Computing    Department of Computer Sciences
Calendar: https://tinyurl.com/yd55mtgd  1210 W. Dayton St. Rm #4257
Phone: (608) 263-7132                   Madison, WI 53706-1685