0

I'm improving a set of gearman workers written in python. They're launched with the basic code:

gm_worker = gearman.GearmanWorker(server_address_list)
gm_worker.register_task('pipeline', pipeline_task_gm_worker)
gm_worker.work()

What I'm looking for is an alternate way to launch the worker so that it will monitor the filesystem for changes to the worker code and restart when it sees them. All the web frameworks support this for easier debugging. Is it possible to do this with gearman workers too?

Janne Karila
  • 24,266
  • 6
  • 53
  • 94
Leopd
  • 41,333
  • 31
  • 129
  • 167
  • Do you mean *restart* processes or *reload* only the module by reaload command and to do additional fixes? Django framework e. g. restarts the development server process. It is useful for easier development and testing, but nightmare when I am *debugging*; therefore Django has now an option to turn off the autoreload. – hynekcer Sep 10 '12 at 18:54
  • I'd be fine with either. I just don't know how to get started since the `work()` method just takes over. – Leopd Sep 10 '12 at 19:37

1 Answers1

0

Restart: solution from Django: A watch dog process is started first, that forks the worker process. Watch dog eventually kills worker if necessary.

Reload: The best and the most general about reloading code without lossing data in memory is Guido's (inventor Python's) code. E.g. reloading code and replacement of old code object in a class object by new code object replaces it also in all instances without loss of any instance data. My advices for reload that helped an user are here. Currently I can safely reload all my or well known code but I would never like to reload a black box - third party unknown code like gearman. Reloading also does not work if some code is currently being traced in the debugger. Restart is transparent.

Community
  • 1
  • 1
hynekcer
  • 14,942
  • 6
  • 61
  • 99