singleton ... again

Chris Angelico rosuav at gmail.com
Thu Feb 13 14:50:06 EST 2014


On Fri, Feb 14, 2014 at 6:03 AM, Roy Smith <roy at panix.com> wrote:
> In article <mailman.6852.1392317509.18130.python-list at python.org>,
>  Ethan Furman <ethan at stoneleaf.us> wrote:
>>
>> You mean use the Borg pattern instead of the Singleton pattern?  As far as I
>> can tell they are two shades of the same
>> thing.  Are there any drastic differences between the two?  Besides one
>> having many instances that share one __dict__
>> and the other just having one instance and one __dict__?
>
> I envision SerialPort being a thin layer on top of a bunch of
> OS-specific system calls to give them a pythonic interface.  Things like
> is_shutdown() and set_bit_rate() presumably turn into ioctls.  No need
> to have any state at all beyond a file descriptor.

I'd go a bit further. The SerialPort instance would have its own
effective state: the file descriptor. Two of them can be created and
one of them closed, and the fd for that one would be closed while the
other stays open. It's then two objects dealing with a common external
facility.

ChrisA



More information about the Python-list mailing list