473,399 Members | 2,278 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,399 software developers and data experts.

Question about the 'code' module

I'm using the code module to implement an interactive interpreter
console in a GUI application, the interpreter running in a separate
thread. To provide clean shutdown of the application, I have to make
sure that objects used in the interpreter thread are deleted when the
thread ends.

I delete the sys.last_type, sys.last_value, and sys.last_traceback
attributes which are set when an exception occured in the interpreter
thread (*). To clean up the '_' symbol that the interpreter maintains,
I have found no other solution than to execute 'console.runsource("0")'
at the end of the thread. Where is this symbol stored? How can I delete
it without the .runsource() call?

(*) It seems to me that the code modules usage of the sys.last_type,
sys.last_value, and sys.last_traceback attributes is not thread safe.
The docs mention that this doesn't matter because there's only one
interactive thread - which does not need to be true when using the code
module. You could easily run several interactive interpreters at the
same time, which is exactly the purpose of this module.

Why is the (non thread-safe) sys.last_traceback used at all? Couldn't
it be replaced with the (thread-safe) sys.exc_info()[2]?

Thomas
Dec 29 '05 #1
1 1234
Thomas Heller wrote:
I'm using the code module to implement an interactive interpreter
console in a GUI application, the interpreter running in a separate
thread. To provide clean shutdown of the application, I have to make
sure that objects used in the interpreter thread are deleted when the
thread ends.

I delete the sys.last_type, sys.last_value, and sys.last_traceback
attributes which are set when an exception occured in the interpreter
thread (*). To clean up the '_' symbol that the interpreter maintains,
I have found no other solution than to execute 'console.runsource("0")'
at the end of the thread. Where is this symbol stored? How can I delete
it without the .runsource() call?


Wild guess: try defining your own sys.displayhook to manage output. This may be
done there, though I'm not really sure. Otherwise, it's done by the
interpreter internally when exec is called on a code object compiled in
'single' mode.

Cheers,

f

Dec 29 '05 #2

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

Similar topics

1
by: Kevin MacKenzie | last post by:
I'm a complete newbie to using Python. I have a small question about importing modules. Is there any difference between the two following statements, and what (if any) are they? >>> from...
2
by: Aubrey Hutchison | last post by:
Question about functions: 1)--- module "A" contains the following X = 999666 #easy to notice value Y = 111222 #easy to notice value Product = 69696969 #easy to...
0
by: David M. Wilson | last post by:
Hello! I maintain a small package for talking to the API of BulkSMS.co.uk. I have been adding support for some new features recently, and found myself slightly indecisive over how best to lay...
8
by: It's me | last post by:
This must be another newbie gotchas. Consider the following silly code, let say I have the following in file1.py: #============= import file2 global myBaseClass myBaseClass =...
6
by: flamesrock | last post by:
ok, so to my knowledge, object oriented means splitting something into the simplest number of parts and going from there. But the question is- when is it enough? For example I have the following...
4
by: Joseph Geretz | last post by:
Our company develops and markets a client/server application which is written in VB6 as a rich Win32 Client/Server application. For a variety of technological reasons we are looking to migrate...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
6
by: Tuvas | last post by:
I know this is probably a very simple question, but I am building a program that is now at about 2400 lines of code in the main module. I need to break it up, however, there are certain variables...
0
by: Patrick.O.Ige | last post by:
I have an sample xml below. I want to do a distinct on the code node and the programDescription. I want the output to be like in a tree structure. So i would like to have PRG004 >Crazy Training...
6
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.