473,491 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cleaning the current environment after a fork

Hey guys

I want to fork a process, but my scope has lots of stuff that the child
won't need. Is it possible to clean the current environment of cruft so it
is collected and freed? Basically I want it to go something like this.
This is my first forking Python app, by the way:

# {{{ My app

import lots, of, stuff

# ...snip...

ret = os.fork()

if ret is not 0:

# clean my environment of lots, of, stuff so they are collected and
# memory is freed

import mymodule
worker = mymodule.MyClass(**kw) # some arguments that I have worked out
worker.Go()
sys.exit()._exit()

# carry on

# }}}

Obviously I only want to selectively clean the environment. I was thinking
something along the lines of:

tokeep = ["kw", "others"]
for obj in dir():
if obj not in tokeep:
delattr(?, obj)

However I can't access the local scope with (del|get|set|has)attr.. can I?

I would like to do it this way instead of os.popen() because there are
structures I'd like my child to have which would be tricky to pass through
shell args.

Any help would be appreciated :-)

Thanks

-Rob
Apr 6 '06 #1
2 1305
> I want to fork a process, but my scope has lots of stuff that the child
won't need. Is it possible to clean the current environment of cruft so it
is collected and freed? Basically I want it to go something like this.
This is my first forking Python app, by the way:


I'm not an expert of this - but if all the reason you want to do this are
memory concerns, AFAIK forking will only make a copy of those memory-pages
that are actually written to by the forked process - for efficiency
reasons.

And even if that wasn't the case: I think as long as you don't run into
memory-troubles, don't do it. Its complex, flaky and thus an unnecessary
source of failure.

Diez
Apr 6 '06 #2
On Thu, 06 Apr 2006 12:47:25 +0200, Diez B. Roggisch wrote:
And even if that wasn't the case: I think as long as you don't run into
memory-troubles, don't do it. Its complex, flaky and thus an unnecessary
source of failure.
Yeah that sounds fair enough. Actually I ran in to threading problems so
I sorted out a way of transferring my data

Thanks

-Rob

Diez


Apr 6 '06 #3

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

Similar topics

4
5885
by: Benoit Dejean | last post by:
hello, i have a question about forking processes atm, i have some code which i want to rewrite os.system("cd ~ && exec " + cmd + " & disown") i want to remove this os.system call
6
2379
by: shellcode | last post by:
the code: ------fork.c------ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> int main() {
27
5931
by: steve | last post by:
I was given the following code, and asked what the possible outputs could be. We're learning about processes and forking. int value; int main(){ int pid, number = 1; value = 2; pid = fork();...
11
8250
by: ramu | last post by:
Hi All, We know that a c function never returns more than one value. Then how come the fork() function returns two values? How it is implemented? Regards
5
4261
by: JDS | last post by:
Hi. I have installed the PCNTL functions on my PHP enabled webserver in the interest of being able to fork a process into the background so I can do some heavy processing but return control of the...
1
5049
by: vduber6er | last post by:
Hi I want to have a wait page while the rest of the cgi does its process, but it seems like the wait page waits till everything is complete and never appears. I've tried forking twice already as...
3
2707
by: thrillseekersforever | last post by:
The questions(A&B) are to fine no# of process running from the below codes. However, I couldn't decipher the solution. Will someone please throw some light on this? Thanks a lot!! A] void...
5
12203
by: JoeW | last post by:
Now before I go into detail I just want to say that this is purely for my own benefit and has no real world usage. I remember way back when the tool for *nix systems called forkbomb was created. I...
0
1178
by: Now You Know | last post by:
Carpet Cleaners Los Angeles Home Carpet Rug Upholstery Cleaning Phone 1 310 925 1720 OR 1-818-386-1022 Local Call California Wide We offer carpet cleaning services such as; Steam Cleaning, Dry...
0
7115
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
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
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
7360
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...
0
5451
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,...
1
4881
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...
0
3086
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...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.