maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Silly small python question: task in a non blocking way? (https://talk.maemo.org/showthread.php?t=70455)

luis 2011-03-01 02:24

Re: Silly small python question: task in a non blocking way?
 
Quote:

Originally Posted by v13 (Post 957608)
It depends on your program:

If you have a cpu-intensive program (let's say a password cracker - that runs all the time) that needs to communicate with the network you may need separate processes (but for the cpu-intensive part).

For most other cases you do this using select/poll or an API that is based on that (like asyncore or twisted).

On the other hand, if you're writing a GUI program you'll have to look at the toolkit's libraries for something that properly interacts with its main loop. Qt for example has a networking module that will fit your needs.

My app is not extremely CPU intensive.... I will think about what you've wrote, but looks like the select/poll thing is close to what I need. I would have to do it on sockets, since I want my app to be cross-platform.


Thanks,
L.

luis 2011-03-01 02:25

Re: Silly small python question: task in a non blocking way?
 
Quote:

Originally Posted by epage (Post 957630)
Take a look at the "login" and "_login" functions in the following file
https://github.com/epage/The-One-Rin...ice/session.py

"login" creates a AsyncLinearExecution which runs "_login" in the foreground thread but everything at a "yield" in a background thread. Looking at the "_login" function this takes what would be two or three callbacks with different kinds of state and simplifies it to a single function.

EDIT: And since I wrote that code, I've generalized it for both Qt and GTK. Makes callback code a lot simpler. Each piece of code after a "yield" is runs as a callback and you would have had to find a way to pass all that state to that callback.

Thanks a lot. I'll look at your code carefully.

Cheers!

L.


All times are GMT. The time now is 15:22.

vBulletin® Version 3.8.8