473,748 Members | 4,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Best" way to "drive" a Python program step by step.

Hi everyone,

I'd be interested in hearing suggestions as to the "best" way to drive
a Python program step by step from another application.

Details:
---------

I have implemented a "Robot" that can be programmed by a user to
perform certain actions. (see Reeborg below for a simple javascript-
based example).

For example, part of a typical program might look like:
=====
move()
turn_left()
move()
for i in range(2):
move()
....
===

I had this working in a desktop based application (see RUR-PLE below),
where the user program was executed via

exec user_code in MyGlobals

and MyGlobals contained appropriate definitions. Having it all
included in a single Python program, I could include time delays in
each instruction [such as move()], so that the user could stop the
program running by clicking on a button, etc., and then step through a
series of instructions one-by-one, and/or resume the automatic
execution.

Now, I want to reproduce this behaviour in a browser based application
(see Crunchy below).

So, I'd like the Python back end to send information (at set
intervals) to the browser and be able to react to input from the
browser (say, a user pressing a "pause" button).

I could try to reimplement the method I used for RUR-PLE some 3 years
ago but I know enough now to realize that the method I used was rather
"inelegant" , but don't know enough to see a better way off-hand.

Any suggestion would be appreciated.

Cheers,
André

Reeborg: http://reeborg.world.googlepages.com/reeborg.html
Crunchy: http://code.google.com/p/crunchy/
RUR-PLE: http://rur-ple.sourceforge.net/
Sep 15 '08 #1
1 2016
On Sep 14, 5:41*pm, André <andre.robe...@ gmail.comwrote:
Hi everyone,

I'd be interested in hearing suggestions as to the "best" way to drive
a Python program step by step from another application.
Andre,

If you want a Javascript program to render the results of a
"syncrhrono use" Python program in "real time," with the ability to
pause, kill, etc., I would suggest a three-tier architecture:

Javascript client -Python mediator -Python target program

The Python target program would be something like this, written in a
very synchronous style:

while True:
send_command_to _javascript_and _wait('move')
send_command_to _javascript_and _wait('turnleft ')

The target program would be simple Python code, and the only minor
magic would be in the send_command_to _javascript_and _wait method,
which would normally just call "print," but when running as a
subprocess, would block until the parent indicates it should proceed.

I think it's useful, especially on this mailing list, to think about
how the Python "mediator" program controls the Python "target"
program. Essentially you want the "target" program to be a subprocess
of the "mediator" program. You will probably want to use the
"Subprocess " module. Look at the "Reading Output of Another Command"
section of the article below:

http://www.oreillynet.com/onlamp/blo...process_1.html

Once you solve the problem of having another Python program control
your "target" program, it's not too big a conceptual leap to have a
Javascript (JS) program control it. I would suggest the following
high level architecture:

1) JS client communicates with Python mediator via HTTP Ajax calls.
2) JS can send HTTP request to mediator to have it start the target
as a subprocess.
3) JS can send HTTP request to mediator to have it deliver data to
target subprocess.
4) Target subprocess can send data back to mediator that is to be
part of the HTTP response.

In your rur-ple application data will be flowing mostly in one
direction. The JS client will simply be telling the Python target to
advance a step, while the Python target will be giving specific
metadata about how to update the world that JS renders. Still,
despite the asymmetrical nature of your app, I would try to think of
it as a two-way exchange of data. The JS program is communicating
what the user wants to do next (usually a generic request to execute
the next instruction), and the Python backend is communicating how to
change the view (usually as a builtin command like move_robot or
highlight_line_ of_code), but ultimately it's all data.

Hope that helps!

Cheers,

Steve
http://webstervanrobot.com/
Sep 15 '08 #2

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

Similar topics

8
50587
by: Alex Ang | last post by:
I have written the following VBScript program. It is stored into a file "map_drive.vbs". It successfully mapped to a network drive \\server1\data. Dim WshNetwork Set WshNetwork = WScript.CreateObject("WScript.Network") sPwd = inputbox("Enter password") WshNetwork.MapNetworkDrive "J:", "\\server1\data", false, "xyz_net\John", sPwd Msgbox "Drives has been map successful"
49
2862
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville Vainio http://www.students.tut.fi/~vainio24
10
1989
by: Carlos Ribeiro | last post by:
Hello all. I'm sending this to the list because I would like to know if someone else has ever stumbled across this one, and also because one possible solution is to patch, or simply "decorate", some of the Python libraries functions (a few of the os and os.path calls). Note: if you're going to reply, please read it *all* before doing so -- I've already explored this problem quite a bit, and found no obvious solution to it yet.
99
6223
by: Jim Hubbard | last post by:
It seems that Microsoft not only does not need the classic Visual Basic developer army (the largest army of developers the world has ever seen), but now they don't need ANY Windows developer at a small or mid-sized business. http://groups-beta.google.com/group/microsoft.public.msdn.general/browse_thread/thread/9d7e8f9a00c1c7da/459ca99eb0e7c328?q=%22Proposed+MSDN+subscription+changes%22&rnum=1#459ca99eb0e7c328 Damn! To be that...
1
2118
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. The fact that I'm using a shared drive may be mute information. The problem is within the same program a second call to fopen does not create a file if the file has been deleted. I would like to use fopen for its pointer return value to solve this.
81
7326
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
7
3372
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. A second call to fopen doesn't create the file if it has been deleted. I would like to use fopen for its pointer return value to solve this. What is the best way to fix this problem?
4
9156
by: Luc The Perverse | last post by:
Hi - I have very little C# programming experience. I am making a software product which calls for an interface almost identical to Windows Explorer - and I wondered if mounting a "virtual drive" would be feasable for me (someone not good at programming) to implement. -- LTP :)
0
5735
Boxcar74
by: Boxcar74 | last post by:
Hi Everybody!!! I have an Issue. I have an Excel file that queries an Access db. I’m trying to have it so I don’t have to keep updating it manually everyday and save it to a network drive with the file name coming from a cell reference and the current date. What I’ve done have the Excel file open via a Batch file and on “Workbook_Open” I run a few macro to refresh the data then remake and save it to the network drive. My...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.