Jump to content


Photo

Cancel a single job in Jobmanager (Task.py)


  • Please log in to reply
31 replies to this topic

#1 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 14:23

Sorry for my noob python question.

 

I am currently writing  plugin to download stuff from the net, I have a list of files that are added in jobmanager and they download fine.

 

I know how to cancel all jobs at the same time:

 


exist = self['movielist'].getCurrent()
                        if exist == None:
                                return

if exist[2] == "Waiting":
                                for job in JobManager.getPendingJobs():
                                        #Value = (job, job.name, job.getStatustext())
                                        #os.system("echo '" + str(Value) + "' > " + "'" + PLUGIN_PATH + "/waiting.txt'")
                                        job.cancel()

Edited by mrdude, 14 July 2017 - 14:28.


Re: Cancel a single job in Jobmanager (Task.py) #2 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 14:29

How do I cancel just one job at a time, Instead of ALL of them - ie I need to replace job.cancel(), with something else so everything doesn't get cancelled - only the job I select from my list. I can't find this info with google, but I assume there is a way to do this. Thanks

 

#for some reason, I can't edit the above post??



Re: Cancel a single job in Jobmanager (Task.py) #3 mrvica

  • Senior Member
  • 1,224 posts

+81
Good

Posted 14 July 2017 - 14:45

for some reason, I can't edit the above post??

https://forums.openp...to-edit-a-post/

Re: Cancel a single job in Jobmanager (Task.py) #4 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 15:07

 

for some reason, I can't edit the above post??

https://forums.openp...to-edit-a-post/

 

I was getting all excited there thinking you had an answer to my python question - oh well back to refreshing my browser :-)



Re: Cancel a single job in Jobmanager (Task.py) #5 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 14 July 2017 - 15:49

You can change your code assuming exit(0) is job name
In the loop you put
If job.name== exit(0):
Job.cancel

Re: Cancel a single job in Jobmanager (Task.py) #6 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 17:45

@mfara57,

 

Here's my function:

def stopjob(self):
                try:
                        exist = self['movielist'].getCurrent()
                        if exist == None:
                                return
                        
                        if exist[2] == "In progress":
                                config.timeshift.isRecording.value = False
                                os.system("killall -9 wget")
                                message = "Stopping " + exist[1] + " - Please Wait!"
                                message2 = "\n\n" + "Would you like to remove the partially downloaded file?"
                                self.session.openWithCallback(self.removepartial, MessageBox, _(message + message2), MessageBox.TYPE_YESNO, default = True, timeout = 10)
                        
                        elif exist[2] == "Waiting":
                                for job in JobManager.getPendingJobs():
                                        Value = (job, job.name, job.getStatustext())
                                        if job.name == exit(0):
                                                os.system("echo '" + str(Value) + "' > " + "'" + PLUGIN_PATH + "/value.txt'")
                                                break
                                        elif job.name != exit(0):
                                                os.system("echo '" + str(exit(0)) + "' > " + "'" + PLUGIN_PATH + "/exit.txt'")
                                                break                                        
                                
                        elif exist[2] != "In progress" or "Waiting":
                                self.session.open(MessageBox, _("You need to select something that's not already Finished!"), MessageBox.TYPE_INFO, timeout = 5) 
        
                except Exception as error:
                        global errormessage
                        errorscreen = "Error in Screen: xcm_TasksScreen" + "\n"
                        errordef = "Error in Def: stopjob" + "\n\n"
                        errormess = "Error Message: " + str(error)
                        errormessage = errorscreen + errordef + errormess
                        self.session.open(xcm_error)

For some reason it should print out a text file - but it freezes the stb with no execption, or text file gets generated (I replaced the job.cancel) for debugging purposes.


Edited by mrdude, 14 July 2017 - 17:47.


Re: Cancel a single job in Jobmanager (Task.py) #7 MiLo

  • PLi® Core member
  • 14,045 posts

+298
Excellent

Posted 14 July 2017 - 19:03

Instead of forking a "wget" and blindly shooting them all down, while calling os.system which is bound to fail to work anyway, you could also just let Enigma download the files for you in a background job using twisted.net downloader. This has the nice advantage that you don't need any subprocess or threading code, and you can monitor and control the download at will.

 

Or at least, you could just send the kill signals from code to the processes you spawned instead of asking the shell to kill them by name, including some innocents.


Real musicians never die - they just decompose

Re: Cancel a single job in Jobmanager (Task.py) #8 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 19:19

@Milo,

 

Yes I changed this part to cancel the 'In progress' file.

if exist[2] == "In progress":
                                config.timeshift.isRecording.value = False
                                for job in JobManager.getPendingJobs():
                                        Value = (job.name)
                                        if job.name == exist[1]:
                                                job.abort()
                                                break                                        
                                message = "Stopping " + exist[1] + " - Please Wait!"
                                message2 = "\n\n" + "Would you like to remove the partially downloaded file?"
                                self.session.openWithCallback(self.removepartial, MessageBox, _(message + me
ssage2), MessageBox.TYPE_YESNO, default = True, timeout = 10)

That sorts the wget problem out, but the waiting jobs don't get cancelled - because job.name always returns the job that's downloading, not the jobs that are waiting - I'll look into that some more.


Edited by mrdude, 14 July 2017 - 19:20.


Re: Cancel a single job in Jobmanager (Task.py) #9 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 14 July 2017 - 19:36

Using enigma http downloader is better than using wget,you can control the download process,show progress bar and cancelling the downloads
attached module may help how to use these functions

Attached Files


Edited by mfaraj57, 14 July 2017 - 19:37.


Re: Cancel a single job in Jobmanager (Task.py) #10 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 19:39

Thanks, I'll have a look at that - cheers.

 

I get most of that with wget/jobmanager already - just need to find a way to cancel waiting jobs - instead of aborting everything:

 

6e2pz8.jpg


Edited by mrdude, 14 July 2017 - 19:43.


Re: Cancel a single job in Jobmanager (Task.py) #11 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 14 July 2017 - 19:47

Also in this loop code in either cases code will exit after first job and will not enumerate restof jobs

                                for job in JobManager.getPendingJobs():
                                        Value = (job, job.name, job.getStatustext())
                                        if job.name == exit(0):
                                                os.system("echo '" + str(Value) + "' > " + "'" + PLUGIN_PATH + "/value.txt'")
                                                break
                                        elif job.name != exit(0):
                                                os.system("echo '" + str(exit(0)) + "' > " + "'" + PLUGIN_PATH + "/exit.txt'")
                                                break          

i assume will be like that

                                for job in JobManager.getPendingJobs():
                                        Value = (job, job.name, job.getStatustext())
                                        if job.name == exit(0):
                                                os.system("echo '" + str(Value) + "' > " + "'" + PLUGIN_PATH + "/value.txt'")
                                                job.canel
                                                break
                                        elif job.name != exit(0):
                                                os.system("echo '" + str(exit(0)) + "' > " + "'" + PLUGIN_PATH + "/exit.txt'")
                                                continue    


Re: Cancel a single job in Jobmanager (Task.py) #12 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 14 July 2017 - 19:59

The code outputs this as text files:

 

exist1.txt - Download: Family Guy - S01E02 - I Never Met the Dead Man

jobname.txt - Download: Family Guy - S01E01 - Death has a Shadow
 
So job.name - this uses Task.py from enigma2, but it's only returning the first entry in the table - (the name if the file downloading), rather than getting the stuff that's waiting, that's what I'm stuck on. The code is like this just now,
 

elif exist[2] == "Waiting":
                                for job in JobManager.getPendingJobs():
                                        Value = (job.name)
                                        if Value == exist[1]:
                                                job.cancel
                                                break
                                        elif Value != exist[1]:
                                                os.system("echo '" + str(exist[1]) + "' > " + "'" + PLUGIN_PATH + "/exist1.txt'")
                                                os.system("echo '" + str(Value) + "' > " + "'" + PLUGIN_PATH + "/jobname.txt'")
                                                continue


Re: Cancel a single job in Jobmanager (Task.py) #13 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 14 July 2017 - 21:15

i think job.cancel() used only for job in progress

you have to use for waiting jobs different function like

job_manager.active_jobs.remove(job)

look at this code

    def abort(self):
        if self.job.status == self.job.NOT_STARTED:
            job_manager.active_jobs.remove(self.job)
            self.close(False)
        elif self.job.status == self.job.IN_PROGRESS and self['cancelable'].boolean == True:
            from Screens.MessageBox import MessageBox
            self.session.openWithCallback(self.stop_job, MessageBox, _('Stop download now,downloaded file will be deleted.'), MessageBox.TYPE_YESNO)
        

    def stop_job(self, result):
        if result:
            self.job.cancel()
          
            try:
               
               
                cmd2 = 'killall -9 wget'
               
                os.system(cmd2)
            except:
                print 'failed to stop download'

           


Re: Cancel a single job in Jobmanager (Task.py) #14 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 15 July 2017 - 07:55

Thanks, that code is in /usr/lib/enigma2/python/Screens/TaskView.py, not in /usr/lib/enigma2/python/Components/Task.py

 

When I call that screen: self.session.open(JobView, currentjob)

 

The download screen opens, and you should be able to press red to cancel the job - but pressing red doesn't seem to do anything. At least it doesn't stop or cancel the job anyway. ???


Edited by mrdude, 15 July 2017 - 07:55.


Re: Cancel a single job in Jobmanager (Task.py) #15 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 15 July 2017 - 08:54

I used nearly same code to stop download in my TSmedia and do not have problem with this but i am using http protocol to download jobs but should apply also to wget 

system notification also generated from job manager module informs about the job is cancelled


Edited by mfaraj57, 15 July 2017 - 08:59.


Re: Cancel a single job in Jobmanager (Task.py) #16 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 15 July 2017 - 11:32

Thanks, I'll have a look at using http instead of wget.



Re: Cancel a single job in Jobmanager (Task.py) #17 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 15 July 2017 - 19:29

The problem with using http downloader you can not stop download easily at least as i know,but for wget as you know by "killall wget..)

job.cancel remove the download job from jobs manager but the download continue,for workaround this problem i deleted the downloaded file then http downloader will stop

attached my tsdownload.py including all functions like stop download,remove from jobsmanager

Attached Files


Edited by mfaraj57, 15 July 2017 - 19:30.


Re: Cancel a single job in Jobmanager (Task.py) #18 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 15 July 2017 - 20:35

Wget cancels the download fine for me (without needing to use killall -9 wget) - basically all that is happening is that the list goes to index 0 and stops/removes the task - unless I put a break into the loop, then the entire task list gets removed.

 

Maybe it's the version of wget you're using, but it works fine for me, and cancels/aborts no problem.

 

The only issue I have is that I don't know how to get the index of a file that's waiting so that I can cancel that specific entry from the task list - I've got the currently downloading task abort working fine, and the cancel everything working fine as well, just the selection of a waiting task is all I need to sort - I'll have a look during the week as my head is melting now as I've tried about everything I can think of, being as I'm a python noob I'm finding it a bit difficult, plus I don't understand all the features of enigma2 such as the ins and out of jobmanager and infobar stuff etc.


Edited by mrdude, 15 July 2017 - 20:36.


Re: Cancel a single job in Jobmanager (Task.py) #19 mrdude

  • Senior Member
  • 90 posts

0
Neutral

Posted 17 July 2017 - 10:58

For anyone reading this thread, I found the issue was a faulty keymap file - I was using openvix, and for some reason they have the red button mapped to cancel instead of red in SetupActions.

 

Once I remapped this back to red - everything is working as it should.

 

The file that gets called is taskview.py

 

The abort code is this:

    def abort(self):
        if self.job.status == self.job.NOT_STARTED:
            job_manager.active_jobs.remove(self.job)
            self.close(False)
        elif self.job.status == self.job.IN_PROGRESS and self['cancelable'].boolean == True:
            self.job.cancel()
        else:
            self.close(False)

Edited by mrdude, 17 July 2017 - 10:58.


Re: Cancel a single job in Jobmanager (Task.py) #20 mfaraj57

  • Senior Member
  • 1,605 posts

+286
Excellent

Posted 17 July 2017 - 13:57

Nice you got the solution finally

i noticed this in openvix and openatv in red and even yellow buttons overrides the local given function,and cause trouble and took long time from me to solve unexplained bugs.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users