Running multiple functions at the same time

Ryno Du preez

I'm new to python, I'm trying to write a small program that will update find files and update then in directory ( this is working )

The problem I'm facing is that I can not get two functions to run at the same time. For example While the code searches for the file and replaces them, also display a small popup window showing an text message that the system is busy. and after the code has completed show a popup message Completed.

!/usr/bin/python
# -*- coding: utf-8 -*-
#Shell script version 2
import os
import shutil
from Tkinter import *
import tkMessageBox
import tkSimpleDialog
from threading import Thread
import threading
import time
from multiprocessing import Process
import sys
from tkinter.ttk import *
import multiprocessing


Search = 'c:\\'
search_folder = ''


class popupWindow(object):
   def __init__(self,parent):
      top=self.top=Toplevel(parent)
      self.l=Label(top,text="Patch is running")
      self.l.pack()
      self.b=Button(top,text='Ok',command=self.cleanup)
      self.b.pack()
   def cleanup(self):
      #self.value=self.e.get()
      self.top.destroy()

class Example(Frame):
    def __init__(self, parent):
       Frame.__init__(self, parent)   

       self.parent = parent

       self.initUI()

    def initUI(self):
        photo = PhotoImage(file="C:\\IMAGE.gif") 
        self.parent.title("Off Line Playe Patch")
        self.style = Style()
        self.style.theme_use("default")

        self.pack(fill=BOTH, expand=1)

        W = Label(self,image=photo)
        W.photo = photo
        W.pack()
        #Button(tk,text='foo',command=bar).pack()
        quitButton = Button(self, text="Apply Patch",command=self.StPatch)
        quitButton.place(x=80, y=0)


    def StPatch(self):
        # Replaces shell.htm with correct file

        def FoundShell():

            for root, dirs, files in os.walk(search_folder):
            for file in files:
            print os.path.join(root,file)
            if file == 'shell.htm':
            print "found file"
            Shell = os.path.join(root,file)
            os.remove(Shell)
            shutil.copy2('./shell.htm',Shell)


     def Hello():
         self.w = popupWindow(self.parent)
         self.parent.wait_window(self.w.top)
         i = 0
         while i < 100000:
           print('hello world')
           i=i+1


        if os.path.exists('C:\Player - Office 2010'):
            print 'Found Folder'
            search_folder = 'C:\Player - Office 2010'
            tkMessageBox.showinfo("Update Done", "Update has been applyed successfuly  ", command=FoundShell())
        else:  # request user to enter path to Directory
            print 'not found'
            search_folder = tkSimpleDialog.askstring('Path', 'Please enter Path to Offline Player', )
            print search_folder
            tkMessageBox.showinfo("Update Done", "Update has been applyed successfuly  ", command=FoundShell())

        #t1 = threading.Thread(target=RunScript(self))
        #t1.start()
        #t1.join()
        #Hello()




    # the join means wait untill it finished

root = Tk()
app = Example(root)

root.mainloop()
João Luiz
import thread
from template import *
from graph import *

try:
   thread.start_new_thread(main,())
   thread.start_new_thread(graph,())
except KeyboardInterrupt:
    thread.exit()

while 1:
   pass

This is an example of how to call 2 functions at a time using multiThreads. Calling Function main with no params "()" from Template file module, and graph function with no params "()" from module graph.

And use this in an auxiliary file called run.py

The while 1 keep the thread running. until KeyboardInterrupt is handled.

Wish this could help!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Running multiple functions at the same time

From Dev

Running more functions at the same time

From Dev

Test while running two functions at the same time

From Dev

Test while running two functions at the same time

From Dev

Running multiple time the same docker image

From Dev

Running multiple sockets at the same time in python

From Dev

how to run multiple functions at same time

From Dev

How to execute multiple functions at the same time in an AsyncTask?

From Dev

Running multiple of same thread at same time with different variables

From Dev

Can I have two multithreaded functions running at the same time?

From Dev

Conflicting functions running at same time from event listener

From Dev

Java Multi-threading prevent two functions running at same time

From Dev

Running three functions at the same time in Python doesn't work

From Dev

Running Time of built in functions

From Java

Trying to stop a single thread out of multiple running at the same time in java

From Dev

Timing in JS - multiple setIntervals running at once and starting at the same time?

From Dev

Run multiple threads at the same time without any running twice or failing

From Dev

SQL Server : same query running multiple times with different execution time

From Dev

Running multiple Kivy apps at same time that communicate with each other

From Dev

Running multiple spiders in the same process, one spider at a time

From Dev

Multiple processes listening to Intel RealSense input running at the same time?

From Dev

Trying to stop a single thread out of multiple running at the same time in java

From Dev

How to Have Multiple Python GUIs Running at the Same time?

From Dev

Running multiple shell instances with different parameters at the same time

From Dev

Running multiple shell instances with different parameters at the same time

From Dev

How to prevent multiple executables from running at the same time on cluster

From Dev

thread not running at the same time

From Dev

thread not running at the same time

From Dev

Running methods in the same time

Related Related

  1. 1

    Running multiple functions at the same time

  2. 2

    Running more functions at the same time

  3. 3

    Test while running two functions at the same time

  4. 4

    Test while running two functions at the same time

  5. 5

    Running multiple time the same docker image

  6. 6

    Running multiple sockets at the same time in python

  7. 7

    how to run multiple functions at same time

  8. 8

    How to execute multiple functions at the same time in an AsyncTask?

  9. 9

    Running multiple of same thread at same time with different variables

  10. 10

    Can I have two multithreaded functions running at the same time?

  11. 11

    Conflicting functions running at same time from event listener

  12. 12

    Java Multi-threading prevent two functions running at same time

  13. 13

    Running three functions at the same time in Python doesn't work

  14. 14

    Running Time of built in functions

  15. 15

    Trying to stop a single thread out of multiple running at the same time in java

  16. 16

    Timing in JS - multiple setIntervals running at once and starting at the same time?

  17. 17

    Run multiple threads at the same time without any running twice or failing

  18. 18

    SQL Server : same query running multiple times with different execution time

  19. 19

    Running multiple Kivy apps at same time that communicate with each other

  20. 20

    Running multiple spiders in the same process, one spider at a time

  21. 21

    Multiple processes listening to Intel RealSense input running at the same time?

  22. 22

    Trying to stop a single thread out of multiple running at the same time in java

  23. 23

    How to Have Multiple Python GUIs Running at the Same time?

  24. 24

    Running multiple shell instances with different parameters at the same time

  25. 25

    Running multiple shell instances with different parameters at the same time

  26. 26

    How to prevent multiple executables from running at the same time on cluster

  27. 27

    thread not running at the same time

  28. 28

    thread not running at the same time

  29. 29

    Running methods in the same time

HotTag

Archive