I'm trying to develop an Ubuntu App using Quickly. When I run an infinite loop in python the Ubuntu App freezes and stops responding. The following is the code I used:
# Code for other initialization actions should be added here.
self.startbutton = self.builder.get_object("startbutton")
def on_startbutton_clicked(self,widget):
while 1 :
if "100" in open("file1.txt").read():
print "success"
exit ()
When I write 100 into file.txt, the terminal prints success but the Ubuntu App will still not respond. So what should I change in my code so that my App won't freeze?
I have changed my while loop
flag=1
while flag :
fp = open("file1.txt","r")
if fp.read()=="100":
print "success"
flag=0
fp.close()
Even then the App freezes
Related
I'm trying to make a program that takes a command and executes it in the console of any operating system and prints the response in python. For this I'm using subprocess.check_output. The program works fine with the ipconfig command (I'm on windows), and the response gets printed after no time. With the notepad command, it opens notepad and only continues when I close notepad. Is it possible to just continue without notepad being closed?
Code:
import subprocess
def executeCommand(command):
return subprocess.check_output(command).decode('ISO-8859-1')
def cmdCommand(command):
pool = ThreadPool(processes=1)
asynch_result = pool.apply_async(executeCommand, [command])
for i in range(3):
if asynch_result.get() is not None:
return asynch_result.get()
sleep(1)
pool.terminate()
return "No result gotten"
print(cmdCommand("ipconfig"))
print(cmdCommand("notepad"))
I am using python 3.8 on windows 10. I am able to run threading programs succesfully on IDLE but, the same programs do not start on command line or when I double click them. The shell pops up and exits quickly even when threads are not started. I even tried to catch any runtime errors and any errors using except but I got neither on IDLE and the program was still terminating abruptly on shell.
Here is an example -
import threading
import time
try:
def func():
for i in range(10):
print(i)
time.sleep(0.1)
t1 = threading.Thread(target = func)
t1.start()
#t1.join() # i tried this also
while t1.is_alive():
time.sleep(0.1) #trying to return back, i added this when the threads were not working
input() #waiting for the user to press any key before exit
except RuntimeError:
print('runtime error')
input()
except: # any error
print('Some error')
input()
I found that I had made a file by the name 'threading.py' in the directory. This file was causing Attribute Error of python because it has the same name as the 'threading' module of python. I renamed it and my programs are working jolly good!
I am using Flask as a local server and initiating a new thread:
rospy.init_node('path_planner')
As I am initiating this thread on a main thread, when I press Ctrl-C, nothing happens and I have to manually kill the process using kill -9
I have tried to signal_handler but still I was not able to kill my program.
Here is my code for POST method, which is used often:
app = Flask(__name__)
app.config["MONGO_URI"] = "mongodb://ed:123#ds029227.mlab.com:2325/test"
mongo = PyMongo(app)
#app.route('/goal', methods=['POST'])
def add_goal():
goal = mongo.db.goal
position = request.json['position']
orientation = request.json['orientation']
goal_id = goal.insert({'position' : position, 'orientation' :
orientation})
new_goal = goal.find_one({'_id' : goal_id})
output = {'position' : new_goal['position'], 'orientation' :
new_goal['orientation']}
position_x = json.loads(position['x'])
position_y = json.loads(position['y'])
return jsonify(output)
And here is my main:
if __name__ == '__main__':
rospy.init_node("path_planner")
app.run(debug=True)
When I run my code, flask server fires up and everything works as expected, POST method does its job. However, when I am done and I need to exit the program, I press Ctrl-C but nothing appears to happen.
try to press the break button. It will break the process I think.
i just started learning blender and its scripting and tried to run its sample code
import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
sens = cont.sensors['mySensor']
actu = cont.actuators['myActuator']
if sens.positive:
cont.activate(actu)
else:
cont.deactivate(actu)
main()
and get the following error:
ImportError: No module named 'bge'
i searched for a solution but couldn't find any.how to solve this problem?
i am using blender 2.65
Running import bge does not work when you press "Run script" or try to issue this command in the terminal. You have to press "P" to activate game engine mode. To run your script, connect a controller to the script.
import 'bge' must be 'blender game', rather than blender rendering
give an 'always' run python scripts in 'game logic editor'
start game
I have a python project. I click on a .py file and hit run with out debugger and the console comes up and the program runs. if I use run with debugger the console flashes and close. there are words on it. but it closes to fast for me to read. I have Set everything in tools I think I can. I have python debugger interactive.
import sys class Test():
def init(self):
var = raw_input("Hit Enter")
t = 'test'
print t
stepB = raw_input("Hit Enter")
a = Test()
place brake pint at t = 'test'