473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to run PyOS_InputHook from python code (i.e. yield to event loops)

Background: PyOS_InputHook is something that gets run when python is
doing raw_input. TkInter and friends use it to run their event loops,
so that their events are handled while python is doing raw_input.

What I'd like to do is run the same function without having to do
raw_input. I.e. I'd like to run whatever event loop is available,
without incorporating any gui-specific code (PyOS_InputHook seems like
a nifty way to accomplish this).

My actual use case is to keep a tkinter application responsive while
launching a background process (and waiting for it to complete!).

My eventual code would be something like:

launch_process_in_thread('bzr pull')

while not is_done:
pyos_inputhook()
time.sleep(0.1)

print "Done!"
Sep 6 '08 #1
3 1676
On Sep 6, 1:00*pm, vivai...@gmail.com (Ville M. Vainio) wrote:
Background: PyOS_InputHook is something that gets run when python is
doing raw_input. TkInter and friends use it to run their event loops,
so that their events are handled while python is doing raw_input.

What I'd like to do is run the same function without having to do
raw_input. I.e. I'd like to run whatever event loop is available,
without incorporating any gui-specific code (PyOS_InputHook seems like
a nifty way to accomplish this).

My actual use case is to keep a tkinter application responsive while
launching a background process (and waiting for it to complete!).

My eventual code would be something like:

launch_process_in_thread('bzr pull')

while not is_done:
* pyos_inputhook()
* time.sleep(0.1)

print "Done!"
I'm still recovering from a hangover, so don't quote me. I think you
want the "after" function:

launch_process_in_thread('bzr pull')
self.update()

def update(self):
while not self.is_done:
self.after(2000, self.update)
Sep 8 '08 #2
Sean DiZazzo <ha**********@gmail.comwrites:

>My eventual code would be something like:

launch_process_in_thread('bzr pull')

while not is_done:
Â* pyos_inputhook()
Â* time.sleep(0.1)

print "Done!"

I'm still recovering from a hangover, so don't quote me. I think you
want the "after" function:

launch_process_in_thread('bzr pull')
self.update()

def update(self):
while not self.is_done:
self.after(2000, self.update)
That's tk-specific, right? I'm looking for a snippet that

- Would not be tied to tk

- Would run sequentially, i.e. the next command would not be entered
before the process has finished. Just like os.system()


Sep 13 '08 #3
ville wrote:
That's tk-specific, right? I'm looking for a snippet that

- Would not be tied to tk
upstream, you said:

"My actual use case is to keep a tkinter application responsive"

</F>

Sep 13 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: beliavsky | last post by:
How do you keep Python code properly indented as you modify it? I use an Emacs-type editor that has a Python mode, so the initial indenting is easy. If I later want to put a 'for' loop (or an 'if'...
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
6
by: nell | last post by:
Hi all, I've developed a testing application in python, and should supply it in a way that no one (lets say they are regular users) will understand it and edit it. The application source is all...
4
by: paritosh mahana | last post by:
Hi all, How can I call python code from my C# code. One thing is to make an ..exe file of the python program and then try to call it from my C# code. But I don't like that idea. Is there any...
3
by: kaens | last post by:
Hey everyone, I'm relatively new to python - I actually picked it up to see how quickly I could start building non-trivial apps with it. Needless to say, I was quite pleased. Anyhow, I'm...
23
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
12
by: WaterWalk | last post by:
Hello. I wonder what's the effective way of figuring out how a piece of python code works. With C I often find it very useful to be able to run the code in step mode and set breakpoints in a...
4
by: jayjaygibbs | last post by:
Is their a program that lets you design a GUI by hand (like gambas) not by code (like wxpython) but the commands are in python? A program similar to gambas or vb Gambas with python code...
3
by: lee.walczak | last post by:
Hi, I have just started writing a GUI using wxpython after finding a limitation using Tkinter. I have read most tutorials on wxpython and slowly becoming accustomed considering I started with...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.