mutual-exclusion

PHP mutual exclusion (mutex)

偶尔善良 提交于 2019-11-26 08:16:21
问题 Read some texts about locking in PHP. They all, mainly, direct to http://php.net/manual/en/function.flock.php . This page talks about opening a file on the hard-disk!! Is it really so? I mean, this makes locking really expensive - it means each time I want to lock I\'ll have to access the hard-disk )= Can anymore comfort me with a delightful news? Edit: Due to some replies I\'ve got here, I want to ask this; My script will run only by one thread, or several? Because if it\'s by one then I

Make sure only a single instance of a program is running

只愿长相守 提交于 2019-11-26 01:41:30
问题 Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I\'ve come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it\'s not really a great idea, maybe there\'s something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like \"lock file\" won\'t work) 回答1: The following code should do the job, it is cross

Make sure only a single instance of a program is running

旧城冷巷雨未停 提交于 2019-11-25 20:31:44
Is there a Pythonic way to have only one instance of a program running? The only reasonable solution I've come up with is trying to run it as a server on some port, then second program trying to bind to same port - fails. But it's not really a great idea, maybe there's something more lightweight than this? (Take into consideration that program is expected to fail sometimes, i.e. segfault - so things like "lock file" won't work) sorin The following code should do the job, it is cross-platform and runs on Python 2.4-3.2. I tested it on Windows, OS X and Linux. from tendo import singleton me =