omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Python not wait for sub Function

    Pythonista
    3
    19
    3345
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DavinE
      DavinE last edited by

      @cvp, Honestly ? xD

      i have no idea why i set this....

      what does @ui.in_background and @on_main_thread exactly

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @DavinE last edited by

        @DavinE There are two base threads in Pythonista and you can force to run a process in The main_thread or in tHe ui one.
        Remove this line and it is still not ok, put the line @on_main_thread

        1 Reply Last reply Reply Quote 0
        • DavinE
          DavinE last edited by

          @cvp like this:

          @on_main_thread
          def generatePDF(...)
          

          and here:

          def setFileNamePDF(self, customer, customer_project, materiallistType)
          

          nothing ?

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @DavinE last edited by

            @DavinE Sincerely, I don't know but personally I would put the @on_main_thread before the other def.

            DavinE 1 Reply Last reply Reply Quote 0
            • DavinE
              DavinE last edited by

              @cvp okay thanks i try it and response to you xD

              1 Reply Last reply Reply Quote 0
              • DavinE
                DavinE @cvp last edited by

                @cvp said:

                @DavinE Sincerely, I don't know but personally I would put the @on_main_thread before the other def.

                it works xD Thanks @cvp

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @DavinE last edited by cvp

                  @DavinE eureka

                  1 Reply Last reply Reply Quote 0
                  • montykit
                    montykit last edited by

                    Hi everyone,

                    Is it possible to launch a python command without waiting for a return ? and therefore start the next command without waiting the previous one to finish ?

                    I searched and asked also on StackOverflow but so far I didn't found what I was looking for...

                    something that look promising might be the
                    1
                    concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
                    as seen here -> https://stackoverflow.com/a/60832288/11943028

                    But this example is focus on results that I don't need. any ideas ?

                    Thank you.


                    https://fashionmentions.com/best-foundation/

                    DavinE cvp 3 Replies Last reply Reply Quote 0
                    • DavinE
                      DavinE @montykit last edited by

                      @montykit,

                      in my case @ui.in_backgroundworks... and don't wait for a return

                      maybe for you too

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp @montykit last edited by cvp

                        @montykit see the threading module, you could start one thread for each command

                        But what do you call a command?

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @montykit last edited by cvp

                          @montykit try

                          import threading
                          
                          class MyThread(threading.Thread):
                          	def __init__(self,cmd):
                          		threading.Thread.__init__(self)
                          		self.run = cmd
                          
                          def cmd1():	
                          	s = 0
                          	for i in range(1000):
                          		s += 1
                          	print(s)
                          	
                          def cmd2():	
                          	s = 0
                          	for i in range(1000):
                          		s += i
                          	print(s)
                          
                          
                          MyThread(cmd1).start()
                          MyThread(cmd2).start()
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors