class TimingMixin():start_time = Noneend_time = Noneexec_time = None@luigi.Task.event_handler(luigi.Event.DEPENDENCY_DISCOVERED)def save_start_time(self):self.start_time = time.time()self.log("Dependency present. Starting task")@luigi.Task.event_handler(luigi.Event.SUCCESS)def save_end_time(self):self.end_time = time.time()import pdb; pdb.set_trace()self.exec_time = time.strftime('%H:%M:%S', time.gmtime(self.end_time - self.start_time))self.log("Task succeded. Time executed (H:M:S): " + self.exec_time)
--
You received this message because you are subscribed to the Google Groups "Luigi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to luigi-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for your quick reply!
What if I want to get the execution_time's value in another function by calling your print_execution_time() function? Like following, "return str(processing_time)" is not a good way to solve this problem. : (
@luigi.Task.event_handler(luigi.Event.PROCESSING_TIME)
def print_execution_time(self, processing_time):
print('### PROCESSING TIME ###: ' + str(processing_time))
return str(processing_time)
Hope you understand my question...
Best,
Anna
Thanks for your quick reply!
What if I want to get the execution_time's value in another function by calling your print_execution_time() function? Like following, "return str(processing_time)" is not a good way to solve this problem. : (
@luigi.Task.event_handler(luigi.Event.PROCESSING_TIME)
def print_execution_time(self, processing_time):
print('### PROCESSING TIME ###: ' + str(processing_time))
return str(processing_time)
Hope you understand my question...
Best,
Anna
On Monday, August 31, 2015 at 3:39:28 PM UTC-7, Samuel Lampa wrote:That should be no problem You can do pretty much anything inside a function that you decorate to be an event handler.
For example, we store all the task information to a task-specific file, in our SciLuigi library:
https://github.com/samuell/sciluigi/blob/d403b1/sciluigi/audit.py#L52-L62
We actually don't use normal luigi outputs for this particular thing (maybe we should), but I think it should not be hard... something like this should work:
class MyTask(luigi.Task):def output(
...
A question please. How do I return worker's name and I'd along with processing time?
Many thanks,
Jianliang
For processing time, you can use the decorator like below and then define your custom method for what you want to do with it. This example just prints it in seconds.
@luigi.Task.event_handler(luigi.Event.PROCESSING_TIME)
def processing_time(task, processing_time):
print('Processing time for task {0} was {1} seconds'.format(task,processing_time)) You can get the worker id/info if you define run() like this. Note, this is somewhat custom for other reasons, so there may be an easier way.
|