16

I tried to develop a simple currency program but I have a problem. When I click on Çevir, the program should calculate money (like an exchange). But I can't do it. PyCharm writes Process finished with exit code 1 when I click Çevir

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import qApp


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
      ....(qtdesigner codes . i skip this part)


        self.pushButton.clicked.connect(self.cevirici)
        self.pushButton_2.clicked.connect(self.cikis)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
   
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_2.setText(_translate("MainWindow", "Birinci Döviz"))
        self.label.setText(_translate("MainWindow", "İkinci Döviz"))
        self.label_3.setText(_translate("MainWindow", "Miktar"))
        self.label_4.setText(_translate("MainWindow", "Sonuç :"))
        self.pushButton.setText(_translate("MainWindow", "Çevir"))
        self.pushButton_2.setText(_translate("MainWindow", "Çıkış Yap"))
    
    def cevirici(self):
        import requests

        import sys

        url = "http://api.fixer.io/latest?base="

        birinci_doviz = self.comboBox.currentText()
        ikinci_doviz = self.comboBox_2.currentText()

        miktar = int(self.lineEdit.currentText())

        response = requests.get(url + birinci_doviz)

        json_verisi = response.json()


        self.lineEdit_2.setText(json_verisi["rates"][ikinci_doviz] * miktar)
    def cikis(self):
        qApp.quit()    

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
Adriaan
  • 17,741
  • 7
  • 42
  • 75
buraks
  • 163
  • 1
  • 1
  • 7
  • 4
    Possible duplicate of [python: Process finished with exit code 1 when using PyCharm and PyQt5](https://stackoverflow.com/questions/34363552/python-process-finished-with-exit-code-1-when-using-pycharm-and-pyqt5) – NovaLogic Dec 25 '17 at 18:21
  • Why doesn't pycharm just show the traceback? The exit code is almost completely useless as a debugging aid. – ekhumoro Dec 25 '17 at 20:04
  • The example code will never return from `app.exec_()` and will therefore never call `sys.exit()`. The `AttributeError` will immediately terminate execution of the script. Recent versions of pyqt5 will also call `qFatal()` whenever an unhandled exception is encountered, unless an excepthook has been installed (see [here](http://pyqt.sourceforge.net/Docs/PyQt5/incompatibilities.html?highlight=qfatal#unhandled-python-exceptions)). In these cases, the process exit code will be platform-specific. On linux systems, it is 134 (`SIGABRT`). – ekhumoro Dec 25 '17 at 20:08
  • I found [this pycharm support thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000176210-Print-Process-finished-with-exit-code-1), which suggests setting the "Emulate terminal in output console" option might show a proper python traceback instead of the useless exit code message. – ekhumoro Dec 25 '17 at 20:24
  • @BSekili. `miktar = int(self.lineEdit.text())`. – ekhumoro Dec 25 '17 at 22:26
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](https://meta.stackexchange.com/q/5221) – Adriaan Oct 18 '22 at 08:38

3 Answers3

34

0 and 1 are exit codes, and they are not necessarily python specific, in fact they are very common.

exit code (0) means an exit without errors or issues.

exit code (1) means there was some issue / problem which caused the program to exit.

The effect of each of these codes can vary between operating systems, but with Python should be fairly consistent.

user3483203
  • 50,081
  • 9
  • 65
  • 94
8

0 and 1 are exit codes.

exit code (0) means an exit without an errors or any issues, can be a compile time error or any dependency issue.

exit code (1) means there was some issue which caused the program to exit. For example if your program is running on port :8080 and that port is currently in used or not closed, then you code ends up with exit code 1

Ashish Kumar
  • 542
  • 4
  • 20
0

Scroll up in your run screen of pycharm. A bug problably printed the exit exception somewhere in the middle of your printlines. This makes it look your program ran normally and suddenly exit with code 1.

Jop
  • 29
  • 1
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – user11717481 Oct 20 '22 at 09:44