Skip to content

Commit

Permalink
Merge pull request #671 from topazproject/tim/Process.times
Browse files Browse the repository at this point in the history
Add Process.times
  • Loading branch information
timfel committed Aug 16, 2013
2 parents 3acaeb9 + bfab884 commit a43eca9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib-topaz/struct.rb
Expand Up @@ -212,4 +212,16 @@ def to_s
return "[...]" if recursion
end
alias inspect to_s

Struct.new('Tms', :utime, :stime, :cutime, :cstime, :tutime, :tstime) do
def initialize(utime=nil, stime=nil, cutime=nil, cstime=nil,
tutime=nil, tstime=nil)
@utime = utime
@stime = stime
@cutime = cutime
@cstime = cstime
@tutime = tutime
@tstime = tstime
end
end
end
2 changes: 0 additions & 2 deletions spec/tags/core/process/times_tags.txt

This file was deleted.

12 changes: 12 additions & 0 deletions topaz/modules/process.py
Expand Up @@ -80,6 +80,18 @@ def method_fork(self, space, block):
else:
return space.newint(pid)

@moduledef.function("times")
def method_times(self, space):
tms = space.find_const(
space.find_const(space.w_object, "Struct"),
"Tms"
)
return space.send(
tms,
"new",
[space.newfloat(t) for t in list(os.times()[0:4])]
)

@moduledef.function("kill")
def method_kill(self, space, w_signal, args_w):
if not args_w:
Expand Down
10 changes: 10 additions & 0 deletions topaz/objects/moduleobject.py
Expand Up @@ -19,6 +19,11 @@ def __init__(self, varname):
W_FunctionObject.__init__(self, varname)
self.varname = varname

def __deepcopy__(self, memo):
obj = super(W_FunctionObject, self).__deepcopy__(memo)
obj.varname = self.varname
return obj

def call(self, space, w_obj, args_w, block):
return space.find_instance_var(w_obj, self.varname)

Expand All @@ -30,6 +35,11 @@ def __init__(self, varname):
W_FunctionObject.__init__(self, varname)
self.varname = varname

def __deepcopy__(self, memo):
obj = super(W_FunctionObject, self).__deepcopy__(memo)
obj.varname = self.varname
return obj

def call(self, space, w_obj, args_w, block):
[w_value] = args_w
space.set_instance_var(w_obj, self.varname, w_value)
Expand Down

0 comments on commit a43eca9

Please sign in to comment.