I'm trying to implement a file server using the code below. However
the locking doesn't work. I can delete while put'ing a file.
Anyone got an idea about why?
best regards,
seb
#! /usr/bin/env python
import Pyro.core, Pyro.naming
from Pyro.errors import PyroError, NamingError
import sys
import urllib
import os
import fcntl
class fileServer(Pyro .core.ObjBase):
basePath = "/home/snot/diku/dist/opg2/files_to_serve"
def __init__(self):
Pyro.core.ObjBa se.__init__(sel f)
self.basePath = self.basePath.s trip("..")
if not os.path.isdir(s elf.basePath) or
os.path.islink( self.basePath):
raise "invalid path"
def get(self, uri):
f = open(self.baseP ath + uri, 'r+')
fcntl.flock(f, fcntl.LOCK_SH)
data = f.read()
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
return data
def put(self, uri, payload):
f = open(self.baseP ath + urllib.unquote_ plus(uri), 'w')
fcntl.flock(f, fcntl.LOCK_EX)
f.truncate()
f.write(payload )
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
def delete(self, uri):
f = open(self.baseP ath + urllib.unquote_ plus(uri), 'w')
fcntl.flock(f, fcntl.LOCK_EX)
os.unlink(self. basePath + uri)
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
try:
Pyro.core.initS erver()
daemon = Pyro.core.Daemo n()
locator = Pyro.naming.Nam eServerLocator( )
print 'Searching for Name Server...'
try:
ns = locator.getNS()
except Pyro.errors.Pyr oError, message:
print message
sys.exit(1)
daemon.useNameS erver(ns)
try:
ns.unregister(" fileServer")
except NamingError:
pass
uri = daemon.connect( fileServer(), "fileServer ")
print "The daemon runs on port:", daemon.port
print "The object's uri is:", uri
daemon.requestL oop()
except KeyboardInterru pt:
ns.unregister(" fileServer")
print "ctrl + c pressed" 1 1757
On 2008-09-08, Seb <se************ ******@gmail.co mwrote:
I'm trying to implement a file server using the code below. However
the locking doesn't work. I can delete while put'ing a file.
Anyone got an idea about why?
[code snipped]
As far as I understand you are writing some kind of server. What isn't clear
is whether the daemon is using threading or forking to handle multiple requests.
If I remember correctly, flock doesn't work well with multiple threads.
--
Antoon Pardon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marc |
last post by:
Hello,
when using flock() I get a permission denied error:
Warning: fopen("<filename>", "r+") - Permission denied in <pathtofile>
on line 7
I do this:
$fileToOpen=substr($PHP_SELF, strrpos($PHP_SELF,"/")+1);
$fileHandle=fopen($fileToOpen, 'r+') or die($php_erormsg);
|
by: Daniel Brunthaler |
last post by:
hi,
i've a problem with file locking.
seems that flock() and gzopen() do not work together. i get the error (or
warning) message ...
Warning: flock(): cannot represent a stream of type ZLIB as a File
Descriptor in ...
when using flock() after gzopen().
|
by: deko |
last post by:
Do I need to use flock() when reading a file into an array? It's possible that
the file in question could be open at the time the file('filename') request is
made. I realize flock() is required when opening a file with fopen() when there
is contention for the file:
$fp=fopen($ctr, 'w');
//only write if we can get lock on file
if (flock($fp, LOCK_EX))
{
fwrite($fp, "0");
|
by: Rex Karz |
last post by:
Newbie here.
I interpret the fine print at
http://us2.php.net/manual/en/function.flock.php
to mean that flock() does not work where the file being locked is
on an NFS filesystem.
The commentary following the "official" description of flock()
offers numerous circumventions broken flock() where the file
needing atomic access is on an NFS filesystem.
|
by: writeson |
last post by:
Hi all,
I've got a PHP program that I've added flock() to in order to protect
multiple scripts trying to write to the same file. After I added the
flock() to the code the performance of the code went way down. Can
anyone tell me if calling flock() on a file handle is particularly
slow?
Thanks,
Doug
| |
by: siliconmike |
last post by:
I've scoured over manual page for flock on http://in2.php.net/flock but
I can't understand a few things:
1. will flock wait until a different process releases the lock ?
2. please clarify this line:
" If you don't want flock() to block while locking, add LOCK_NB "
what does "block" mean above?
|
by: Babu |
last post by:
Hi,
I have an application that maintains its configuration file. This file
is read frequently but written to very rarely. There may be several
processes attempting to read and write to the config file.
The application reads the configuration file into a buffer, inflicts
changes on the buffer and writes the buffer to the file.
The intended logic for writing the buffer into the config file is as
follows
# create a copy of config.txt say...
|
by: Time Waster |
last post by:
Is this a stupid use of flock:
FILE *fp=fopen(SOME_FILE_CONSTANT,"r+");
flock(fileno(fp),LOCK_EX);
something important here, including reads and a write to fp
flock(fileno(fp),LOCK_UN);
fclose(fp);
Does this accomplish real locking, or just narrow down the
race quite a bit? (Race existing between the unlock and the
|
by: xucs007 |
last post by:
I ran following 2 programs (lock1, lock2) at almost same time,
to write either "123456", or "222" to file "aaa" at the same time.
But I often just got "222456" in "aaa" .
Is this a bug of python fcntl module ? See 2 programs I ran:
#!/usr/bin/env python
import fcntl, time
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |