0

python3.6

I want to make file1 and file2 to work as exec.

tak.py @@main file

from tkinter import *
import subprocess

class App(Frame):

 def __init__(self, okno=None):
     Frame.__init__(self, okno)
     self.okno = okno
     self.init_window()

 def init_window(self):
     self.okno.title("Ping checker")
     self.okno.minsize(width=1000, height=800)
     self.okno.maxsize(width=1000, height=800)
     self.pack(fill=BOTH, expand=1)
     quitbutton = Button(self, text="Exit", height=5, width=25, 
                         command=self.client_exit, fg='black',
                         bg='white', activeforeground='white',             
                          activebackground='black', bd='3')
     startbutton = Button(self, text="Start",height=5, width=25, 
                       command=self.client_start_ping, fg='black',
                       bg='white', activeforeground='white', 
     activebackground='black', bd='3')
     quitbutton.place(x=800, y=700)
     startbutton.place(x=15, y=700)

 def client_exit(self):
     exit()

 def client_start_ping(self):
     var = StringVar()
     label = Message(root, textvariable=var, relief=RAISED)
     label.config(width=666)
     label.place(x=15, y=1)
     try:
         output = subprocess.check_output("fastafping.exe")
     except subprocess.CalledProcessError as e:
         raise RuntimeError("command '{}' return with error (code {}): 
                           {}".format(e.cmd, e.returncode, e.output))
     var.set(output)


root = Tk()
app = App(root)
root.mainloop()

fastafping.py 2nd file

import multiprocessing
import subprocess
import cx_Oracle


def client_start_ping(job_q, results_q, badresults_q):
    y = "ping -c l "
    while True:
        ip = job_q.get()
        if ip is None:
            break

        try:
            subprocess.check_output(str(y) + ip)
            results_q.put(ip)

        except:
            badresults_q.put(ip)


if __name__ == '__main__':
    ipaddress =[]
    jobs = multiprocessing.Queue()
    results = multiprocessing.Queue()
    badresults = multiprocessing.Queue()
    con = cx_Oracle.connect('#####/#####@##.#.#.#/##')
    cur = con.cursor()
    cur.execute("Update IP_CHECK_TAB SET CHECK_ = 'N'")
    cur.execute("Update IP_CHECK_TAB SET CHECK_='Y'")
    cur.execute("Select IP from IP_CHECK_TAB  Order By Ip")
    output = {}
    for a in cur:
        ipaddress.append(a[0])
    pool_size = len(ipaddress)
    pool = [multiprocessing.Process(target=client_start_ping, args=(jobs, 
results, badresults))
         for i in range(pool_size)]
    for p in pool:
        p.start()
    for i in ipaddress:
        jobs.put(i)
    for p in pool:
        jobs.put(None)
    for p in pool:
        p.join()
    while not results.empty():
        ip = results.get()
        print(ip + " : Connected")
        cur.execute("Update IP_CHECK_TAB SET STATUS='ok',STATUS_INFO = 
                    sysdate Where IP = '" + ip + "'")
        output[ip] = "host appears to be up"
    while not badresults.empty():
        ip = badresults.get()
        print(ip + " : Not connected")
        cur.execute("Update IP_CHECK_TAB SET STATUS='nok',STATUS_INFO = 
                    sysdate Where IP = '" + ip + "'")
        output[ip] = "host is not connected"
    con.commit()
    cur.close()
    con.close()

When i am trying to make file tak.py executable with pyinstaller. Output is:

  Traceback (most recent call last):
 File "fastafping.py", line 25, in <module>
cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be 
loaded: "C:\app\Praktyka\product\12.1.0\client_1\oci.dll is not the correct 
architecture". See 
https://oracle.github.io/odpi/doc/installation.html#windows 
for help
[4288] Failed to execute script fastafping
Exception in Tkinter callback
Traceback (most recent call last):
  File "tak.py", line 33, in client_start_ping
  File "subprocess.py", line 336, in check_output
 File "subprocess.py", line 418, in run
subprocess.CalledProcessError: Command 'fastafping.exe' returned non-zero 
 exit 
    status 4294967295.

  During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tkinter\__init__.py", line 1702, in __call__
  File "tak.py", line 35, in client_start_ping
 RuntimeError: command 'fastafping.exe' return with error (code 4294967295): 
b''

I am trying to do everything that i know to do. My applicaton is pinging every ip from oracle database using multiprocessing. All i want is make this in gui and make this work on other pc without installing python

Tigerly
  • 3
  • 2

1 Answers1

1

The error is clear - exit() call from method def client_exit(self) is undefined. You can try to use sys.exit() (and add import sys). Or look for other solution here.

kvorobiev
  • 5,012
  • 4
  • 29
  • 35
  • Maybe but it isn't about exit, I cant start program becouse of not working client_start_ping – Tigerly Sep 25 '18 at 09:06
  • @Tigerly Why you think so? From error message from your post `File "tak.py", line 25, in client_exit`. – kvorobiev Sep 25 '18 at 09:11
  • This is error when i am trying to exit from interface, i showed you all errors that occurs. My program is working perfectly without making him exe – Tigerly Sep 25 '18 at 10:12
  • @Tigerly You wrote 'When i am trying to make file tak.py executable with pyinstaller'. `pyinstaller` raise 'NameError' on unknown name `exit()`. When you just run your script with python you doesn't see this error, because interpreter will visit `client_exit` only on exit. – kvorobiev Sep 25 '18 at 10:17
  • @Tigerly And now you can pack your code as execution file and run on other machine? – kvorobiev Sep 25 '18 at 10:28
  • @Tigerly 1. You can without errors create executables from both python files, right? 2. You got an error in runtime? If yes, post error text. – kvorobiev Sep 25 '18 at 10:44
  • first file givnig error cus of 2nd file that don;t work correctly – Tigerly Sep 25 '18 at 11:26
  • @Tigerly You got an error at runtime or when trying to make executables? – kvorobiev Sep 25 '18 at 11:29
  • @Tigerly Try following: 1. Generate executable file for `fastafping.py` file - this will result in fastafping.exe/fastafping depending on your OS). 2. Replace `output = subprocess.check_output("python fastafping.py")` with `output = subprocess.check_output("fastafping.exe")`. 3. Try to convert tak,py to executable. – kvorobiev Sep 25 '18 at 11:45
  • okay i tried and same errors, i tried only tak.py and no errors, everything is working on tak.py. I have big problem with fastafping.py becouse of none-stop duplicating process when i am running it in .exe one minute and from 1process i have 1000 and my computer is crashing down – Tigerly Sep 26 '18 at 06:55