Forcing QgsTask to cancel in QGIS plugin? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Canceling task currently running in background using PyQGis?How to write an address search plugin?How to store a password during one QGIS work session?How do I properly import python sklearn to QGIS PyQt plugin?python - Composer plugin menu catch-22Open QGIS project files in exclusive mode / alert if project file already in useST_Contains. Check for true/false in Python cursorHow to handle User Created Project Variables with qgis APIHow to open QGIS project properties focused on “CRS” and select choosen projectionQGIS 3 Python plugin psycopg2 Postgres Notify/Listen Live ConnectionCanceling task currently running in background using PyQGis?

Can an iPhone 7 be made to function as a NFC Tag?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

New Order #6: Easter Egg

Flight departed from the gate 5 min before scheduled departure time. Refund options

What does 丫 mean? 丫是什么意思?

How to ask rejected full-time candidates to apply to teach individual courses?

Rationale for describing kurtosis as "peakedness"?

I can't produce songs

Tannaka duality for semisimple groups

RSA find public exponent

Is there public access to the Meteor Crater in Arizona?

Why weren't discrete x86 CPUs ever used in game hardware?

What would you call this weird metallic apparatus that allows you to lift people?

Why are vacuum tubes still used in amateur radios?

What is the "studentd" process?

Nose gear failure in single prop aircraft: belly landing or nose-gear up landing?

GDP with Intermediate Production

Where is the Next Backup Size entry on iOS 12?

What does Turing mean by this statement?

Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?

Tips to organize LaTeX presentations for a semester

Is it dangerous to install hacking tools on my private linux machine?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

A term for a woman complaining about things/begging in a cute/childish way



Forcing QgsTask to cancel in QGIS plugin?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Canceling task currently running in background using PyQGis?How to write an address search plugin?How to store a password during one QGIS work session?How do I properly import python sklearn to QGIS PyQt plugin?python - Composer plugin menu catch-22Open QGIS project files in exclusive mode / alert if project file already in useST_Contains. Check for true/false in Python cursorHow to handle User Created Project Variables with qgis APIHow to open QGIS project properties focused on “CRS” and select choosen projectionQGIS 3 Python plugin psycopg2 Postgres Notify/Listen Live ConnectionCanceling task currently running in background using PyQGis?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to force closing Qgis project (QgsTask) in some point




NOTE:

QgsProject.instance().clear() # NOT WORKING



QgsTaskManager().cancelAll() # NOT WORKING



QgsTask.cancel() # NOT WORKING




task.canCancel() # FALSE





project = QgsProject.instance()
project.clear() # NOT WORKING
QgsTaskManager().cancelAll() # NOT WORKING
tasks = QgsApplication.taskManager().activeTasks()
for task in tasks:
print (task.canCancel()) # False
print (task.description()) # Loading “C:/Users/User/Desktop/some_project.qgs”
print (task.flags()) # <qgis._core.QgsTask.Flags object at 0x000002330527E4C8>

task.cancel() # NOT WORKING


Is there any way to force closing project or task or change flag QgsTask.CanCancel to True ?










share|improve this question
























  • duplicate gis.stackexchange.com/questions/318503/…

    – Fran Raga
    Apr 12 at 9:58











  • that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

    – ncica
    Apr 12 at 10:01











  • when you created the task did you put the flag canCancel?

    – Fran Raga
    Apr 12 at 10:55











  • No :/ I just open the project : Project -> open... @FranRaga

    – ncica
    Apr 12 at 10:57











  • Add sample creating task object

    – Fran Raga
    Apr 12 at 11:01


















2















I want to force closing Qgis project (QgsTask) in some point




NOTE:

QgsProject.instance().clear() # NOT WORKING



QgsTaskManager().cancelAll() # NOT WORKING



QgsTask.cancel() # NOT WORKING




task.canCancel() # FALSE





project = QgsProject.instance()
project.clear() # NOT WORKING
QgsTaskManager().cancelAll() # NOT WORKING
tasks = QgsApplication.taskManager().activeTasks()
for task in tasks:
print (task.canCancel()) # False
print (task.description()) # Loading “C:/Users/User/Desktop/some_project.qgs”
print (task.flags()) # <qgis._core.QgsTask.Flags object at 0x000002330527E4C8>

task.cancel() # NOT WORKING


Is there any way to force closing project or task or change flag QgsTask.CanCancel to True ?










share|improve this question
























  • duplicate gis.stackexchange.com/questions/318503/…

    – Fran Raga
    Apr 12 at 9:58











  • that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

    – ncica
    Apr 12 at 10:01











  • when you created the task did you put the flag canCancel?

    – Fran Raga
    Apr 12 at 10:55











  • No :/ I just open the project : Project -> open... @FranRaga

    – ncica
    Apr 12 at 10:57











  • Add sample creating task object

    – Fran Raga
    Apr 12 at 11:01














2












2








2








I want to force closing Qgis project (QgsTask) in some point




NOTE:

QgsProject.instance().clear() # NOT WORKING



QgsTaskManager().cancelAll() # NOT WORKING



QgsTask.cancel() # NOT WORKING




task.canCancel() # FALSE





project = QgsProject.instance()
project.clear() # NOT WORKING
QgsTaskManager().cancelAll() # NOT WORKING
tasks = QgsApplication.taskManager().activeTasks()
for task in tasks:
print (task.canCancel()) # False
print (task.description()) # Loading “C:/Users/User/Desktop/some_project.qgs”
print (task.flags()) # <qgis._core.QgsTask.Flags object at 0x000002330527E4C8>

task.cancel() # NOT WORKING


Is there any way to force closing project or task or change flag QgsTask.CanCancel to True ?










share|improve this question
















I want to force closing Qgis project (QgsTask) in some point




NOTE:

QgsProject.instance().clear() # NOT WORKING



QgsTaskManager().cancelAll() # NOT WORKING



QgsTask.cancel() # NOT WORKING




task.canCancel() # FALSE





project = QgsProject.instance()
project.clear() # NOT WORKING
QgsTaskManager().cancelAll() # NOT WORKING
tasks = QgsApplication.taskManager().activeTasks()
for task in tasks:
print (task.canCancel()) # False
print (task.description()) # Loading “C:/Users/User/Desktop/some_project.qgs”
print (task.flags()) # <qgis._core.QgsTask.Flags object at 0x000002330527E4C8>

task.cancel() # NOT WORKING


Is there any way to force closing project or task or change flag QgsTask.CanCancel to True ?







qgis python pyqgis qgis-plugins






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 12 at 10:03







ncica

















asked Apr 12 at 9:47









ncicancica

2587




2587












  • duplicate gis.stackexchange.com/questions/318503/…

    – Fran Raga
    Apr 12 at 9:58











  • that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

    – ncica
    Apr 12 at 10:01











  • when you created the task did you put the flag canCancel?

    – Fran Raga
    Apr 12 at 10:55











  • No :/ I just open the project : Project -> open... @FranRaga

    – ncica
    Apr 12 at 10:57











  • Add sample creating task object

    – Fran Raga
    Apr 12 at 11:01


















  • duplicate gis.stackexchange.com/questions/318503/…

    – Fran Raga
    Apr 12 at 9:58











  • that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

    – ncica
    Apr 12 at 10:01











  • when you created the task did you put the flag canCancel?

    – Fran Raga
    Apr 12 at 10:55











  • No :/ I just open the project : Project -> open... @FranRaga

    – ncica
    Apr 12 at 10:57











  • Add sample creating task object

    – Fran Raga
    Apr 12 at 11:01

















duplicate gis.stackexchange.com/questions/318503/…

– Fran Raga
Apr 12 at 9:58





duplicate gis.stackexchange.com/questions/318503/…

– Fran Raga
Apr 12 at 9:58













that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

– ncica
Apr 12 at 10:01





that is also my question (without answer). I separate problem, a little bit simplify it, because I made some progress @FranRaga

– ncica
Apr 12 at 10:01













when you created the task did you put the flag canCancel?

– Fran Raga
Apr 12 at 10:55





when you created the task did you put the flag canCancel?

– Fran Raga
Apr 12 at 10:55













No :/ I just open the project : Project -> open... @FranRaga

– ncica
Apr 12 at 10:57





No :/ I just open the project : Project -> open... @FranRaga

– ncica
Apr 12 at 10:57













Add sample creating task object

– Fran Raga
Apr 12 at 11:01






Add sample creating task object

– Fran Raga
Apr 12 at 11:01











1 Answer
1






active

oldest

votes


















1














I add an example of a task to load a project, For cancel only uncomment



task.cancel()


Sample



def completed(exception, result=None):
if exception is None:
if result is None:
print('Completed with no exception and no result probably manually canceled by the user')
else:
print("completed " , result['task'])
# But layers not show on canvas and refresh not work
# Trick (probably don't know the right method)
root = QgsProject.instance().layerTreeRoot()
layers = QgsProject.instance().mapLayers()
map_canvas_layer_list = [l for l in layers.values()]
for layer in map_canvas_layer_list:
node=root.findLayer( layer.id())
v=node.isVisible ()
node.setItemVisibilityChecked(not v)
node.setItemVisibilityChecked(v)
break
else:
print ("Failed Task")
raise exception

def LoadProject(task,mFile):
project = QgsProject.instance()
project.read(mFile)
return 'task': task.description()

mFile = r'D:sample.qgs'
task = QgsTask.fromFunction("Loading project",LoadProject,mFile=mFile,on_finished=completed, flags=QgsTask.CanCancel)

QgsApplication.taskManager().addTask(task)

# task.cancel() # For cancel , uncomment if you want cancel it
while QgsApplication.taskManager().countActiveTasks() > 0:
QCoreApplication.processEvents()


Note: I suppose there is a method to make them visible, but I thought of that as a trick



tested QGIS 3.6.1



I hope it helps you






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318585%2fforcing-qgstask-to-cancel-in-qgis-plugin%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    I add an example of a task to load a project, For cancel only uncomment



    task.cancel()


    Sample



    def completed(exception, result=None):
    if exception is None:
    if result is None:
    print('Completed with no exception and no result probably manually canceled by the user')
    else:
    print("completed " , result['task'])
    # But layers not show on canvas and refresh not work
    # Trick (probably don't know the right method)
    root = QgsProject.instance().layerTreeRoot()
    layers = QgsProject.instance().mapLayers()
    map_canvas_layer_list = [l for l in layers.values()]
    for layer in map_canvas_layer_list:
    node=root.findLayer( layer.id())
    v=node.isVisible ()
    node.setItemVisibilityChecked(not v)
    node.setItemVisibilityChecked(v)
    break
    else:
    print ("Failed Task")
    raise exception

    def LoadProject(task,mFile):
    project = QgsProject.instance()
    project.read(mFile)
    return 'task': task.description()

    mFile = r'D:sample.qgs'
    task = QgsTask.fromFunction("Loading project",LoadProject,mFile=mFile,on_finished=completed, flags=QgsTask.CanCancel)

    QgsApplication.taskManager().addTask(task)

    # task.cancel() # For cancel , uncomment if you want cancel it
    while QgsApplication.taskManager().countActiveTasks() > 0:
    QCoreApplication.processEvents()


    Note: I suppose there is a method to make them visible, but I thought of that as a trick



    tested QGIS 3.6.1



    I hope it helps you






    share|improve this answer



























      1














      I add an example of a task to load a project, For cancel only uncomment



      task.cancel()


      Sample



      def completed(exception, result=None):
      if exception is None:
      if result is None:
      print('Completed with no exception and no result probably manually canceled by the user')
      else:
      print("completed " , result['task'])
      # But layers not show on canvas and refresh not work
      # Trick (probably don't know the right method)
      root = QgsProject.instance().layerTreeRoot()
      layers = QgsProject.instance().mapLayers()
      map_canvas_layer_list = [l for l in layers.values()]
      for layer in map_canvas_layer_list:
      node=root.findLayer( layer.id())
      v=node.isVisible ()
      node.setItemVisibilityChecked(not v)
      node.setItemVisibilityChecked(v)
      break
      else:
      print ("Failed Task")
      raise exception

      def LoadProject(task,mFile):
      project = QgsProject.instance()
      project.read(mFile)
      return 'task': task.description()

      mFile = r'D:sample.qgs'
      task = QgsTask.fromFunction("Loading project",LoadProject,mFile=mFile,on_finished=completed, flags=QgsTask.CanCancel)

      QgsApplication.taskManager().addTask(task)

      # task.cancel() # For cancel , uncomment if you want cancel it
      while QgsApplication.taskManager().countActiveTasks() > 0:
      QCoreApplication.processEvents()


      Note: I suppose there is a method to make them visible, but I thought of that as a trick



      tested QGIS 3.6.1



      I hope it helps you






      share|improve this answer

























        1












        1








        1







        I add an example of a task to load a project, For cancel only uncomment



        task.cancel()


        Sample



        def completed(exception, result=None):
        if exception is None:
        if result is None:
        print('Completed with no exception and no result probably manually canceled by the user')
        else:
        print("completed " , result['task'])
        # But layers not show on canvas and refresh not work
        # Trick (probably don't know the right method)
        root = QgsProject.instance().layerTreeRoot()
        layers = QgsProject.instance().mapLayers()
        map_canvas_layer_list = [l for l in layers.values()]
        for layer in map_canvas_layer_list:
        node=root.findLayer( layer.id())
        v=node.isVisible ()
        node.setItemVisibilityChecked(not v)
        node.setItemVisibilityChecked(v)
        break
        else:
        print ("Failed Task")
        raise exception

        def LoadProject(task,mFile):
        project = QgsProject.instance()
        project.read(mFile)
        return 'task': task.description()

        mFile = r'D:sample.qgs'
        task = QgsTask.fromFunction("Loading project",LoadProject,mFile=mFile,on_finished=completed, flags=QgsTask.CanCancel)

        QgsApplication.taskManager().addTask(task)

        # task.cancel() # For cancel , uncomment if you want cancel it
        while QgsApplication.taskManager().countActiveTasks() > 0:
        QCoreApplication.processEvents()


        Note: I suppose there is a method to make them visible, but I thought of that as a trick



        tested QGIS 3.6.1



        I hope it helps you






        share|improve this answer













        I add an example of a task to load a project, For cancel only uncomment



        task.cancel()


        Sample



        def completed(exception, result=None):
        if exception is None:
        if result is None:
        print('Completed with no exception and no result probably manually canceled by the user')
        else:
        print("completed " , result['task'])
        # But layers not show on canvas and refresh not work
        # Trick (probably don't know the right method)
        root = QgsProject.instance().layerTreeRoot()
        layers = QgsProject.instance().mapLayers()
        map_canvas_layer_list = [l for l in layers.values()]
        for layer in map_canvas_layer_list:
        node=root.findLayer( layer.id())
        v=node.isVisible ()
        node.setItemVisibilityChecked(not v)
        node.setItemVisibilityChecked(v)
        break
        else:
        print ("Failed Task")
        raise exception

        def LoadProject(task,mFile):
        project = QgsProject.instance()
        project.read(mFile)
        return 'task': task.description()

        mFile = r'D:sample.qgs'
        task = QgsTask.fromFunction("Loading project",LoadProject,mFile=mFile,on_finished=completed, flags=QgsTask.CanCancel)

        QgsApplication.taskManager().addTask(task)

        # task.cancel() # For cancel , uncomment if you want cancel it
        while QgsApplication.taskManager().countActiveTasks() > 0:
        QCoreApplication.processEvents()


        Note: I suppose there is a method to make them visible, but I thought of that as a trick



        tested QGIS 3.6.1



        I hope it helps you







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 12 at 12:29









        Fran RagaFran Raga

        3,44311123




        3,44311123



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318585%2fforcing-qgstask-to-cancel-in-qgis-plugin%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

            Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

            QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output