This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-create Unix domain sockets when binding,
to avoid losing the monitor on alternating restarts
- Loading branch information
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
========================= | ||
Using Unix-domain sockets | ||
========================= | ||
|
||
Passing a string to start causes it to bind to a Unix-domain socket. | ||
|
||
Let's set up logging so we can see what's happening: | ||
|
||
>>> import logging | ||
>>> import os | ||
>>> import stat | ||
>>> import time | ||
>>> import zc.monitor | ||
>>> import zope.testing.loggingsupport | ||
|
||
>>> loghandler = zope.testing.loggingsupport.InstalledHandler( | ||
... None, level=logging.INFO) | ||
|
||
Passing a path as the argument to start causes a Unix socket to be bound: | ||
|
||
>>> path = "testing.sock" | ||
|
||
>>> zc.monitor.start(path) | ||
'testing.sock' | ||
|
||
>>> m1 = os.stat(path) | ||
>>> stat.S_ISSOCK(m1.st_mode) | ||
True | ||
|
||
Attempting to start the monitor at the same path again succeeds, but | ||
causes a new socket to be created: | ||
|
||
>>> zc.monitor.start(path) | ||
'testing.sock' | ||
|
||
>>> m2 = os.stat(path) | ||
>>> stat.S_ISSOCK(m2.st_mode) | ||
True | ||
|
||
>>> m1.st_ino == m2.st_ino | ||
False | ||
|
||
Clean up: | ||
|
||
>>> os.unlink(path) | ||
>>> loghandler.uninstall() |